2017-04-25 150 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