We can find an element using the css locator with Selenium webdriver. To identify the element with css, the expression should be tagname[attribute='value'].We can also specifically use the id attribute to create a css expression.With id, the format of a css expression should be tagname#. For example, input#txt [here input is the tagname and the txt is the value of the id attribute].With class, the format of css expression should be tagname. . For example, input.cls-txt [here input is the tagname and the cls-txt is the value of the class attribute].If there are n children of a parent element, and ... Read More
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
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
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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP