获取元素不可见

时间:2017-04-25 06:25:08

标签: selenium-webdriver selenium-chromedriver

enter image description here

我尝试过以下的expaths

driver.findElement(By.xpath("/html/body/div/div/div/div[2]/div[2]/div[1]/div/div[1]/button[1]/img")).click();
driver.findElement(By.xpath("/html/body/div/div/div/div[2]/div[2]/div[1]/div/div[1]/button[1]")).click();

它不起作用。请建议我。

这是页面来源

<button class="btn btn-success btn-fab demo-switcher-fab ng-scope" ng-if="innoassist_AuthUserdata.roles[21].create_permission != 0" ui-sref="App.addequipment" data-toggle="tooltip" tooltip="Add Asset" tooltip-placement="left" href="#/App/addequipment">
<img src="../theme-assets/images/plus.png">
</button>

1 个答案:

答案 0 :(得分:0)

尝试等到目标按钮变为可见:

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@id='firsttimeloading']")));
WebElement button = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@tooltip='Add Asset']")));
button.click();