Found 871 Articles for Automation Testing

How to find an element using the “XPath” in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:44:11

7K+ Views

We can find an element using the xpath locator with Selenium webdriver.To identify the element with xpath, the expression should be //tagname[@attribute='value'].To identify the element with xpath, the expression should be //tagname[@class='value']. There can be two types of xpath – relative and absolute. The absolute xpath begins with / symbol and starts from the root node upto the element that we want to identify.For example, /html/body/div[1]/div/div[1]/aThe relative xpath begins with // symbol and does not start from the root node. For example, //img[@alt='tutorialspoint']Let us see the html code of the highlighted element starting from the root.The absolute xpath for the ... Read More

What is the exact meaning of webdriver.chrome.driver and where this system property is located in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:43:32

4K+ Views

To launch the Chrome browser, we have to use the System.setProperty method. This method takes the parameters – webdriver.chrome.driver and the path of the chromedriver.exe file.So webdriver.chrome.driver is basically the property name and the path of the chromedriver.exe is the value. Thus, the System.setProperty method is used to configure the browser driver path.The Selenium client library communicates with the ChromeDriver via the JSON Wire Protocol. The Chrome browser driver acts like a link between the Selenium implementation code and the Chrome browser. The System.setProperty is the beginning line that requires to be added to our test prior creation of webdriver ... Read More

How to switch different browser tabs using Python Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:39:11

6K+ Views

We can switch different browser tabs using Selenium webdriver in Python using the method switch_to.window. By default, the webdriver has access to the parent window.Once another browser tab is opened, the switch_to.window helps to switch the webdriver focus to the tab. The window handle of the browser window where we want to shift is passed as a parameter to that method.The method window_handles contains the list of all window handle ids of the opened browsers. The method current_window_handle is used to hold the window handle id of the browser window in focus.Syntaxp = driver.current_window_handle parent = driver.window_handles[0] chld = driver.window_handles[1] ... Read More

How to switch back from a frame to default in Selenium Webdriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:35:15

7K+ Views

We can switch back from a frame to default in Selenium webdriver using the switchTo().defaultContent() method. Initially, the webdriver control remains on the main web page.In order to access elements within the frame, we have to shift the control from the main page to the frame with the help of the switchTo().frame and pass the frame name/id or webelement of the frame as a parameter to that method.Finally, again we can switch the control to the main page with the switchTo().defaultContent() method. A frame is identified in the html code with the tag names – frame, iframe or frameset.Let us ... Read More

How to know the exact time to load a page using Selenium WebDriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:34:09

4K+ Views

We can determine the exact time to load a page using Selenium webdriver. We can capture the time before the page load with help of the System.currentTimeMillis method.After the URL for the application is launched, we have to wait for the page to be loaded completely with the help of the explicit wait condition. Once the expected criteria for the element is met, we shall again record the current time.The difference between the time recorded prior and post the page load will measure the exact time to load a page.Syntaxlong s = System.currentTimeMillis();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; ... Read More

How to use relative xpath for locating a web-element by particular Attribute in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:30:56

1K+ Views

We can use relative xpath for locating web-element by particular attribute value. A relative xpath begins from the element to be located and not from the root.It begins with the // symbol. It’s advantage is that even if an element is deleted or added in the DOM, the relative xpath for a specific element remains unaffected. To obtain a relative path by an attribute, the xpath expression is //tagname[@attribute='value'].Let us identify the below highlighted element on the page with the help of the alt attribute.Syntaxl = driver.find_element_by_xpath("//img[@alt='tutorialspoint']")Examplefrom selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/about/about_careers.htm") ... Read More

How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:29:59

9K+ Views

We can send keyboard input to a textbox on a webpage in Selenium webdriver in Python using the method send_keys. The text to be entered is passed as a parameter to that method.To perform keyboard actions, we can also use the send_keys method and then pass the class Keys. as a parameter to that method. To use the Keys class, we have to add from selenium.webdriver.common.keys import Keys statement to the code.Syntaxi = driver.find_element_by_name("txt") i.send_keys("Selenium") i.send_keys(Keys.RETURN)Let us try to send keyboard input to a textbox on a page −Examplefrom selenium import webdriver from selenium.webdriver.common.keys import Keys #set chromodriver.exe path driver ... Read More

How to display all items in the list in the drop down in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:29:29

3K+ Views

We can display all items in the list in the dropdown with Selenium webdriver using the Select class. A dropdown is represented by select tag and itsoptions are represented by option tag.To obtain all the list of items we have to use the method getOptions. Its return type is list. Then we have to iterate through this list and obtain it with the help of the getText method.Let us see the html code of a dropdown along with its options – Please select an option, Option 1 and Option 2.SyntaxWebElement d = driver.findElement(By.tagName("select")); Select l = new Select(d); List m ... Read More

How to loop through a menu list on a webpage using Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:27:44

7K+ Views

We can loop through a menu list on a webpage using Selenium webdriver.In a webpage, a list is represented by an ul tag and it consists of elements with li tag. Thus the li tag can be said as the child of ul.First, we have to identify the element with ul tag with any locator, then traverse through its li sub-elements with the help of a loop. Finally, use the method getText to obtain the text on the li elements.Let us try to identify the menu list on a webpage.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; import ... Read More

How to get details of a webpage like url, title name, domain name etc using Javascript Executor in Selenium?

Debomita Bhattacharjee
Updated on 06-Apr-2021 08:13:33

709 Views

We can get details of a web page like url, title, domain name of webpage using JavaScript Executor in Selenium webdriver. Selenium can execute JavaScript commands with the help of the executeScript method. The command to be executed is passed as a parameter to that method.SyntaxTo get the page title, JavascriptExecutor j = (JavascriptExecutor) driver; String s = j.executeScript("return document.title;").toString();To get the current URL, String p = j.executeScript("return document.URL;").toString();To get the domain, String d = j.executeScript("return document.domain;").toString();Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class JavaScrptScope{    public static void main(String[] args) {       System.setProperty("webdriver.gecko.driver", ... Read More

Advertisements