我在网站上遇到js元素的问题。 Selenium没有看到我的xpath,因为我认为这个元素隐藏在Js背后
我已经习惯了 wait.until(ExpectedConditions .elementToBeClickable .... When I want check this element I can't. I see js. on map. Of course I've found this element by (Firebug,firepath) but Selenium does not see and can't click
driver.findElement(By.xpath(".//*[@id='gmap']/div/div[1]/div[3]/div[3]/div[6]"));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='gmap']/div/div[1]/div[3]/div[3]/div[4]")));
driver.findElement(By.xpath(".//*[@id='gmap']/div/div[1]/div[3]/div[3]/div[4]")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='gmap']/div/div[1]/div[3]/div[3]/div[16]")));
driver.findElement(By.xpath(".//*[@id='gmap']/div/div[1]/div[3]/div[3]/div[16]")).click();
这个元素Selenium看不到。
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='gmap']/div/div[1]/div[2]")));
driver.findElement(By.xpath(".//*[@id='gmap']/div/div[1]/div[2]")).click();
答案 0 :(得分:0)
你有各种各样的可能性。
1)也许您的元素将opacity
属性设置为0,因此您可以通过jQuery将其设置为1并使其可见:
WebDriver driver = new YOUR_DRIVER();
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor)driver).executeScript("$('YOUR_ELEMENT').css('opacity','1');");
}
2)当您必须点击元素时,您可以将其z-index
值更改为页面中“最明显的”:
WebDriver driver = new YOUR_DRIVER();
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor)driver).executeScript("$('YOUR_ELEMENT').css('z-index','100');");
}
3)你可以隐藏你的JS。
...