Found 871 Articles for Automation Testing

Python selenium browser driver.back().

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:40:29

10K+ Views

We can navigate back in the browser with Selenium webdriver. There are multiple ways to achieve this. The back() method is used to move back to the prior browser page. This method only is applicable if we jump from webpage to another.We can also move back in the browser with the help of a Javascript Executor in Selenium. It has the execute_script() method which allows Selenium to run Javascript commands. We have to execute the Javascript command window.history.go(-1) to go back to the previous page.Examplefrom selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch a webpage driver.get("https://www.tutorialspoint.com/about/about_careers.htm") print("Current Page title: ... Read More

Using Selenium Web Driver to retrieve value of a HTML input.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:34:35

12K+ Views

We can get the value of a HTML input with Selenium webdriver. This is achieved with the help of the getAttribute() method. To retrieve the value of the field with tagname input, we have to pass the value as parameter to the getAttribute() method.Let us consider an html code for a html input.We have no value attribute for the field in the DOM. However we shall get the field value as displayed with getAttribute() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class InputVal{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");   ... Read More

How to hold key down with Selenium?

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:28:26

6K+ Views

We can hold a key down with Selenium webdriver. We mostly utilize the CONTROL/SHIFT/ALT keys to hold down and then click on other keys. So, only mentioning the modifier keys like keys.CONTROL/ keys.SHIFT or Keys.ALT is not sufficient.To hold down a key simultaneously while another key is being pressed, we use the keyDown() and keyUp() methods. Both these methods accept the modifier key as a parameter.The action of these two methods on a key yields a special functionality of a key. All these methods are a part of Actions class in Selenium. We have to add the import org.openqa.selenium.interactions.Actions package ... Read More

Key press in (Ctrl+A) Selenium WebDriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:12:55

19K+ Views

We can perform key press of (CTRL+A) with Selenium Webdriver. There are multiple ways to do this. We can use the Keys.chord() method to simulate this keyboard action.The Keys.chord() method helps to press multiple keys simultaneously. It accepts the sequence of keys or strings as a parameter to the method. To press CTRL+A, it takes, Keys.CONTROL, "a" as parameters.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class PressCtrlA{    public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/index.htm";     ... Read More

Find elements inside forms and iframe using Java and Selenium WebDriver.

Debomita Bhattacharjee
Updated on 18-Sep-2020 06:08:24

1K+ Views

We can find elements inside form and iframe with Selenium webdriver. A form in an html document is represented by atag. A form may contain multiple elements inside it. A form can be submitted with a submit() or a click() method.Let us see a form with fields email and password.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; public class FormElements{    public static void main(String[] args) {  System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.linkedin.com/";       driver.get(url);       driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);       // ... Read More

How to perform right click using Selenium ChromeDriver?

Debomita Bhattacharjee
Updated on 18-Sep-2020 05:36:00

555 Views

We can perform right click using Selenium ChromeDriver. On right clicking on a webelement, the context menu gets displayed. For example, if we right click on a text area, an additional menu with several options come up.Actions class in Selenium is responsible for simulating this mouse operation. The Actions class provides the contextClick() method to carry out this action and select any option from the context menu.To perform this entire operation, we shall first move the mouse to the middle of the element with moveToElement() method, then apply contextClick() method. Furthermore, we have to execute the build() method to execute the ... Read More

How to find specific lines in a table using Selenium?

Debomita Bhattacharjee
Updated on 28-Aug-2020 13:27:12

3K+ Views

We can find specific lines in a table with Selenium webdriver. A table is identified in an html document with tag. Each table comprises a tag that represents rows and a tag to represent columns. To traverse through table rows and columns we use the method findElements().To count the total number of rows in table we use size() method available for list −List l=driver.findElements(By.tagName("tr")); int s= l.size();To count the total number of columns in table we use size() method available for list −List m=driver.findElements(By.tagName("td")); int t= m.size();Let us consider the below table and get the ... Read More

Clicking an element using javascript vs actions vs webdriver?

Debomita Bhattacharjee
Updated on 28-Aug-2020 13:24:17

589 Views

We can click on an element using javascript, Actions class and webdriver methods. Selenium can execute commands in Javascript with the help of the execute_script() method.We have to import org.openqa.selenium.JavascriptExecutor in our code to work with a javascript executor. In order to click an element, first we have to move to that element with mouse movements. We can execute mouse movement with the help of the Actions class in Selenium.We have to use the moveToElement() method. This method shall perform mouse movement till the middle of the element and then perform click followed by build() and perform() methods. We have ... Read More

Find and click element by title Python Selenium.

Debomita Bhattacharjee
Updated on 28-Aug-2020 13:21:15

17K+ Views

We can find and click elements by title in Selenium webdriver. An element can be identified with a title attribute with xpath or css selector. With the xpath, the expression should be //tagname[@title='value']. In css, the expression should be tagname[title='value'].Let us take an html code for an element with a title attribute.The xpath to identify the element should be //a[@title='Tutorialspoint'] and the css expression should be a[title='Tutorialspoint']. Once the element is identified we can use the click() method for clicking on it.ExampleCode Implementation.from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") # implicit wait for 5 seconds driver.implicitly_wait(5) # maximize with ... Read More

How to wait until an element is present in Selenium?

Debomita Bhattacharjee
Updated on 15-Sep-2023 00:54:08

27K+ Views

We can wait until an element is present in Selenium Webdriver. This can be done with the help of synchronization concept. We have an explicit wait condition where we can pause or wait for an element before proceeding to the next step.The explicit wait waits for a specific amount of time before throwing an exception. To verify if an element is present, we can use the expected condition presenceOfElementLocated.ExampleCode Implementation.import 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.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class ElementPresenceWait{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");     ... Read More

Advertisements