2017-04-25 244 views
0

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> 
+0

你的XPath的是因为相对性可怕。请阅读为什么要使用绝对xpath而不是相对的。 – demouser123

回答

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(); 
+0

尝试使用您的代码并获取以下错误消息未知错误:元素<按钮ng-if =“innoassist_AuthUserdata.roles [21] .create_permission!= 0”ui-sref =“App.addequipment”data-toggle =“tooltip” tooltip =“添加资产”...不可点击点(1305,102)。其他元素将收到点击:

...

+0

S其预计工作感谢您的更新 –

+0

是否有任何理由拒绝答案?你还需要改进建议的解决方案吗? – Andersson