Selenium
Creating Object Repository in Selenium WebDriver: XML & Properties file
What is an Object Repository? An object repository is a common storage location for all objects. In...
Image links are the links in web pages represented by an image which when clicked navigates to a different window or page.
Since they are images, we cannot use the By.linkText() and By.partialLinkText() methods because image links basically have no link texts at all.
In this case, we should resort to using either By.cssSelector or By.xpath. The first method is more preferred because of its simplicity.
In the example below, we will access the "Facebook" logo on the upper left portion of Facebook's Password Recovery page.
We will use By.cssSelector and the element's "title" attribute to access the image link. And then we will verify if we are taken to Facebook's homepage.
package newproject; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class MyClass { public static void main(String[] args) { String baseUrl = "https://www.facebook.com/login/identify?ctx=recover"; System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get(baseUrl); //click on the "Facebook" logo on the upper left portion driver.findElement(By.cssSelector("a[title=\"Go to Facebook home\"]")).click(); //verify that we are now back on Facebook's homepage if (driver.getTitle().equals("Facebook - log in or sign up")) { System.out.println("We are back at Facebook's homepage"); } else { System.out.println("We are NOT in Facebook's homepage"); } driver.close(); } }
Result
Conclusion:
This is all to clicking images. Accessing image link is done using By.cssSelector()
What is an Object Repository? An object repository is a common storage location for all objects. In...
What is Selenium Webdriver? Selenium Webdriver is an open-source collection of APIs which is used...
Some web application, have a functionality to drag web elements and drop them on defined area or...
TestNG is a Testing framework, that covers different types of test designs like a unit test,...
For DateTime selection, HTML5 has a new control shown below. Above page can be accessed here If we...
If a simple XPath is not able to find a complicated web element for our test script, we need to...