I am having trouble with clicking at an element of a menu which is written like this:
<div class="menu">
<ul class="tabs ctrlTabsProfile">
<li class="active" data-tab="tabDetail">User Details</li>
<li data-tab="tabEmail">Email</li>
<li data-tab="tabPass">Change password</li>
<li data-tab="tabAdress">Account Details</li>
</ul>
</div>
I have tried these:
driver.findElement(By.linkText("Account Details")).click();
driver.findElement(By.cssSelector("li[data-tab=tabAdress")).click();
driver.findElement(By.xpath("li[data-tab='tabAdress']")).click();
also tried listing the elements but got null
only :
for(WebElement el : driver.findElements(By.cssSelector(".tabs.ctrlTabsProfile"))) {
try {
assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*Account Details[\\s\\S]*$"));
} catch (Error e) {
System.out.println("Not found: \"Account Details\".");
}
String s = el.getAttribute("data-tab");
System.out.println(s);
if(s.equals("tabAdress")) {
driver.findElement(By.xpath("li[data-tab='tabAdress']")).click();
}
}
Solutions? Sugestions? Errors?
Well, for one, your xpath selector is incorrect.
should be:
edit:
And your css selector is incorrect as well.
should be:
edit #2:
and:
will only work if the element is a link, which in this case it is not.