Selenium Automation Q&A
Selenium Automation Q&A
Selenium Automation Q&A
findElements();
syntax: List<WebElement> elementName = driver.findElements(By.LocatorStrategy("LocatorValue"));
Returns a list of web elements
Returns an empty list if there are no web elements matching the locator strategy
It will find a collection of elements whose match the locator strategy.
Each Web element is indexed with a number starting from 0 just like an array
Eg:
1. /bookstore -> Selects the root element bookstore
2. bookstore/book -> Selects all book elements that are children of bookstore
3. //book -> Selects all book elements no matter where they are in the document
4. bookstore//book -> Selects all book elements that are descendant of the bookstore element, no matter where they
are under the bookstore element
5. //@lang -> Selects all attributes that are named lang
Collect all the links in the web page based on <a> tag.
Send HTTP request for the link and read HTTP response code.
Find out whether the link is valid or broken based on HTTP response code.
Repeat this for all the links captured.
10. How to login to any site if it is showing an Authentication Pop-Up for Username and Password?
Sample code:
String URL = "http://" + rajkumar + ":" + myPassword + "@" + www.softwaretestingmaterial.com;
driver.get(URL);
Alert alert = driver.switchTo().alert();
alert.accept();