我试图在使用extjs创建的网页上选择一个标签。 FirePath正确突出显示选项卡但单击事件不起作用。 Selenium投掷元素不可见错误。
Exception in thread "main"\org.openqa.selenium.ElementNotVisibleException: element not visible
(Session info: chrome=57.0.2987.133)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64)
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 38 milliseconds
这是HTML代码:
我试图选择一个名为Details的标签,其标识为tabDetail。
<a class="x-tab x-unselectable x-box-item x-tab-default x-noicon x-tab-noicon x-tab-default-noicon x-top x-tab-top x-tab-default-top x-tab-after-title" role="button" hidefocus="on" unselectable="on" tabindex="0" id="tabDetail" style="right: auto; left: 143px; top: 0px; margin: 0px;"><span id="tabDetail-btnWrap" class="x-tab-wrap" unselectable="on"><span id="tabDetail-btnEl" class="x-tab-button"><span id="tabDetail-btnInnerEl" class="x-tab-inner x-tab-inner-center" unselectable="on"> Detail </span><span role="img" id="tabDetail-btnIconEl" class="x-tab-icon-el " unselectable="on" style=""></span></span></span></a>
答案 0 :(得分:0)
您需要等到元素可见。使用显式等待 -
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[2]")));
// Now click on element
driver.findElement(By.xpath("//div[2]")).click();