0

How do I select in image on and click on it using Selenium web driver? Say if it says this

<style type="text/css"> <ul id="nav"> <li> <li> <li> <li> <li> <a href="dashboard.action">My Dashboard</a> </li> </ul>

Would I use

driver.findElement(By.linkText("My Dashboard")).click();

or something else?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user6401108
  • 3
  • 1
  • 6

3 Answers3

1

If you want to click on link in your example, you can use the selector you wrote, different kinds of css selectors (for example, By.cssSelector("#nav a") (looks for a link inside the "nav" list) or By.cssSelector("a[href='dashboard.action']") (looks for a link with specific href)) or using xPath selectors.