Location Strategies
Choosing a Location Strategy
- Selenium webdriver uses 8 different locators to find the elements on a web page. The following are the list of object identifier or locators supported by selenium.
- Id - Selcects element with the specified @id attribute.
- Name Select first element with the specified @name attribute.
- Linktext - Select link (anchor tag) element which contains text matching the specified link text
- Partial Linktext - Select link (anchor tag) element which contains text matching the specified partial link text
- Tag Name - Locate Element using a Tag Name .
- Class name - Locate Element using a class Name ..
- Css Select the element using css selectors.
- Xpath - Locate an element using an XPath expression.
Navigate Back And Forward On The Browser
...
driver.navigate().refresh();
Elements
Check If An Element Exists
To check an specific web element being present on the web page you may want to use the id "element-id" method.
driver.findElements(By.id("element-id")).size() != 0
Check If Element is Visible
The above method works well to check if an element exists on page. However, sometimes an element may not be visible and you cannot perform any action on it. Thus, to check whether an element is visible or not use the below code.
Code Block | ||
---|---|---|
| ||
WebElement element = driver.findElement(By.id("element-id")); if(element instanceof Rendered WebElement){ System.out.println("Element Visible"); } else{ System.out.println("Element Not Visible"); } |
Handling Files
Upload Image to Page
...