I have a weird problem:
When I locate an element via:
WebElement e1 = driver.findElement(By.xpath("//div1"));
WebElement e2 = e1.findElement(By.xpath("//.[@class='c2']"));
e2.click();
I can't click e2, because: "Element < div class="c2" > could not be scrolled into view."
BUT when I locate e2 via:
WebElement e2 = driver.findElement(By.xpath("//div1//.[@class='c2']"));
e2.click();
it works. (Also when checking e2.getLocation()
the coordinates are different, and only correct in the second snippet).
I think Selenium doesn't like the "//.", because:
WebElement e1 = driver.findElement(By.xpath("//div1"));
WebElement e2 = e1.findElement(By.xpath("div[@class='c2']"));
e2.click();
also works.
Any idea how I can use the any ( .
) selector there? ( .[@class='c2']
can not be found)
[EDIT] I already have e1 and therefore need to search on this element via e1.findElement(...)
WebElement e2 = e1.findElement(By.xpath("//.[@class='c2']"));
this is same as finding element as driver.findElement(By.xpath("//.[@class='c2']"));
because you haven't given current node as reference
you should be using:
e1.findElement(By.xpath(".//*[@class='c2']"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.