selenium
2017-03-01 47 views 0 likes 
0

任何人都可以請幫助我通過硒代碼擊中javascript鏈接。硒JavaScript鏈接

這是檢查代碼和鏈接名稱是應用程序。

目前我在下面的所有代碼列表中使用,但它仍然沒有打開應用程序鏈接。

driver.findElement(By.id("I6")).click(); 
driver.findElement(By.xpath("//img[@ src='/ibm/console/images/arrow_collapsed.gif']")).click(); 
driver.findElement(By.xpath("//span[contains(text(),'Applications']")).click(); 
JavascriptExecutor js = (JavascriptExecutor) driver; 
WebElement element = driver.findElement(By.xpath("//*[contains(text(),Applications')]")); 
js.executeScript("arguments[0].click;", element); 
WebElement element1 = driver.findElement(By.xpath("//span[contains(text(),'Applications']")); 
element1.click(); 
driver.findElement(By.xpath("//a[@href='javascript:expandCollapse('6');]")).click(); 
driver.findElement(By.xpath("//div[@id='I6']/..//a[contains(text(),'Applications')]")).click(); 
+0

這裏還有什麼之後,你發生點擊它或者你得到一個異常?分享日誌,如果有任何 – Andersson

+0

請檢查檢查代碼細節 –

+0

回答

0

嘗試點擊WebElement使用javascript這種方式。

WebElement element = driver.findElement(By.xpath("//span[contains(text(),'Applications']")); 
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element); 

我嘗試用你的這個html代碼:

<img src="/ibm/console/images/arrow_expanded.gif" title="Collapse" alt="Collapse" id="I6" border="0" align="absmiddle"> <img src="/ibm/console/images/arrow_collapsed.gif" title="Expand" alt="Expand" id="I6" border="0" align="absmiddle"> <a style="color:#000000;text-decoration:none;" href="javascript:expandCollapse('6');" title="Applications"><img src="/ibm/console/images/arrow_collapsed.gif" title="Expand" alt="Expand" id="I6" border="0" align="absmiddle"><span dir="ltr">Applications</span></a> 

參考圖片瞭解更多詳情:

enter image description here

+0

是@Jainish,我試過,但還是沒有反映或點擊鏈接 –

+0

不可能的,它是WebSphere部署的公司網址。您無權訪問網址。 –

+0

是的,這真的很有幫助謝謝 –

0

糾正我,如果我錯了,有錯字的你所有的xpath像:

driver.findElement(By.xpath("//span[contains(text(),'Applications']")).click(); \\missed `)` in contains method 

如果看仔細地方'失蹤和地方(),好離開它,請嘗試以下xpath,讓我們知道仍然面臨着同樣的問題

driver.findElement(By.xpath("//a[@title='Applications']")).click(); 

driver.findElement(By.xpath("//a[contains(.,'Applications')]")).click(); 
相關問題