Found 871 Articles for Automation Testing

How to click button Selenium Python?

Debomita Bhattacharjee
Updated on 24-Aug-2023 21:24:12

45K+ Views

We can click a button with Selenium webdriver in Python using the click() method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname, or css.Then we have to apply the click() method on it. A button in html code is represented by button tagname. The click operation can also be performed with the help of the JavaScript Executor.Selenium can execute JavaScript command with the help of execute_script() method and the JavaScript command - arguments[0].click() and the webelement locator are passed as a parameter to this methodSyntaxl=driver.find_element_by_id("btn"); l.click(); ... Read More

What are the different ways of handling authentication popup window using Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:36:40

504 Views

We can handle authentication pop-up window using Selenium webdriver by incorporating the username and password within the application URL. The format of an URL along with credential should be − https://username:password@URLLet us launch a web page having the authentication pop-up generated at page load −The user Name and Password fields are having value as admin.If we ignore this pop-up on clicking the Cancel button, we shall be navigated to the below page.If proper credentials are entered and then the OK button is clicked, we shall be navigated to the below page.In the above example, to handle the authentication pop-up, using ... Read More

How can I clear text of a textbox using Python Selenium WebDriver?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:34:27

3K+ Views

We can clear text of a textbox with Selenium webdriver in Python using the clear method. First of all, we have to identify the text box with the help of any of the locators like id, css, name, class, xpath, css, or class.Then we have to enter text into it with the help of the send_keys method. Finally, to clear it we have to use the clear method. We can verify if the text has been cleared with the help of the get_attribute method.Syntaxl = driver.find_element_by_id('txt') l.clear()Let us try to clear the text from the below edit box.Examplefrom selenium import ... Read More

How can I get Webdriver Session ID in Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:31:13

7K+ Views

We can get the webdriver session id with Selenium webdriver using the SessionId class. A session id is a distinctive number that is given to the webdriver by the server.This number is utilized by the webdriver to establish communication with the browser. The commands in our Selenium tests are directed to the browser with the help of this session id. The method getSessionId is used to obtain the webdriver session id.SyntaxSessionId s = ((RemoteWebDriver) driver).getSessionId();Exampleimport org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.remote.RemoteWebDriver; public class BrwSessionId{    public static void main(String[] args) {       //set ... Read More

How to avoid the pop-up window in chrome browser with Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:30:50

2K+ Views

We can avoid the pop-up window in Chrome browser with Selenium webdriver using the ChromeOptions class. We have to create an object of this class and apply the setExperimentalOption method to it. We shall create a Map and insert the below Chrome browser preference to it −profile.default_content_setting_values.notifications, and set its value to 2.The above browser preference shall be passed as a parameter to the method setExperimentalOption and finally added to the webdriver object.SyntaxMap pf = new HashMap(); pf.put("profile.default_content_setting_values.notifications", 2); ChromeOptions p = new ChromeOptions(); p.setExperimentalOption("prefs", pf);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.HashMap; import java.util.Map; import org.openqa.selenium.WebDriver; public class PopupDisable ... Read More

How can I delete an element in Selenium using Python?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:30:25

6K+ Views

We can delete an element in Selenium webdriver using Python with the help of JavaScript Executor. Selenium is not capable of modifying the structure of DOM directly.It has the feature of injecting JavaScript into the webpage and changing the DOM with the help execute_script method. The JavaScript command to be used is passed as a parameter to this method.JavaScript command to delete an element is −var l = document.getElementsByClassName("tp-logo")[0]; l.parentNode.removeChild(l);The above script is to be passed as a parameter to the execute_script method.Let us try to remove the highlighted logo from the below page −Examplefrom selenium import webdriver #set chromodriver.exe ... Read More

Selenium WebDriver: I want to overwrite value in field instead of appending to it with sendKeys using Java

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:29:51

1K+ Views

We can overwrite the value in the field instead of appending to it with sendKeys in Selenium webdriver. This can be done by using the Keys.chord method.It returns a string and can be applied to any web element with the help of the sendKeys method.To overwrite a value, we shall first select it with CTRL+A keys and then pass the new value. Thus, Keys.CONTROL, A and the new value are passed as parameters to the Keys.chord method.SyntaxString n = Keys.chord(Keys.CONTROL, "A"); WebElement l = driver.findElement(By.name("q")); l.sendKeys(n, "Tutorialspoint");Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Keys; public class ... Read More

How to launch Edge browser with Selenium Webdriver?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:29:11

7K+ Views

We can launch Edge browser with Selenium webdriver by using the Microsoft webdriver. We should also ensure that we are having the machine with the Windows 10 operating system.Navigate to the below link to download the Microsoft Edge driver executable file − https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/Once the page is launched, scroll down to the Downloads section, then choose and click the link which is compatible with our local Edge browser version.A zip file gets created, once the download is completed successfully. We have to then unzip the file and save it in a desired location. Then, set the path of the msedgedriver.exe file. ... Read More

How can I handle multiple keyboard keys using Selenium Webdriver?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:21:31

2K+ Views

We can handle multiple keyboard keys in Selenium webdriver by using the method Keys.chord. The multiple keyboard keys to be handled are passed as parameters to this method.The return type of the Keys.chord method is a string and can be applied to an element with the help of the sendKeys method. For example, in order to perform a select operation on text entered inside an edit box we require the keys ctrl+a to be pressed simultaneously.SyntaxString k = Keys.chord(Keys.CONTROL, "A"); driver.findElement(By.name("q")).sendKeys(k);Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Keys; public class MultipleKeys{    public static void main(String[] ... Read More

How to open new tab in same browser and switch between them using Selenium?

Debomita Bhattacharjee
Updated on 07-Apr-2021 08:17:45

6K+ Views

We can open new tabs in the same browser and switch between them using Selenium webdriver. Firstly, to open a new tab in the same browser we have to take the help of the methods – Keys.chord and sendKeys.The parameters Keys.CONTROL and Keys.ENTER are passed to the Keys.chord method. This method yields a string value and in turn passed as a parameter to the sendKeys method.SyntaxString n = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.id("open-tab")).sendKeys(n);Once the second tab is opened, the getWindowHandles method is used to hold all the window handle ids in a Set. To shift the focus of the webdriver object to ... Read More

Advertisements