2013-12-17 191 views
0

無法點擊使用Selenium鏈接 - webdriver的:當我檢查按鈕無法點擊Continue按鈕 - 硒的webdriver

的Win7以下是代碼:

一個ID =「continue_button鉻「disabled =」false「class =」button button-large ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only「href =」#「role =」button「aria-disabled =「false」>

span class =「ui-button-text」> span class =「button-content」>繼續

我曾嘗試以下方法並沒有什麼作品:

driver.findElement(By.xpath("//*[@id='continue_button']")).click(); 
driver.findElement(By.xpath("//a[contains(..,'Continue')]")).click(); 
JavascriptExecutor js = (JavascriptExecutor) driver; 
js.executeScript("document.querySelector(\"a[id$='continue_button']\").click()"); 
+0

等待按鈕嘗試首先在調試,然後嘗試單擊driver.verify()。verifyElementPresent(通過) –

回答

-1

哎做檢查按鈕是否位於一個框架或不..

0
options=driver.find_elements_by_class_name("button-content") 
for i in options: 
    if(i.text=="Continue"): 
     i.click() 

上面的代碼是蟒蛇。通過翻譯成java來嘗試上面的代碼,我希望它能夠完美工作......任何疑問都會讓我知道。

+0

如果你想要一個以上的元素,你需要使用'.find_elements_by_class_name( )'列表來遍歷,就像這裏介紹的那樣。 –

+0

對不起,我的錯誤..謝謝 –

0

你可以試試這個,

new WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#continue_button span.button-content"))).click(); 

上面的代碼將等待60秒的內容公開程度,如果位於,元素被點擊其他異常將被拋出。

0
if(driver.getTitle().contains("Error")) 
    driver.navigate().to("javascript:document.getElementById('overridelink').click()"); 
+0

如果你解釋爲什麼*你的代碼解決了這個問題會更好。見[回答]。 – brasofilo

0

也許該鏈接部分隱藏在DOM中。您可以嘗試使用下面的代碼段單擊隱藏(或部分隱藏)的元素。

WebElement element = driver.findElement(By.xpath("//a[@id='continue_button'])); 
JavascriptExecutor js = (JavascriptExecutor) driver; 
js.executeScript("arguments[0].click();", element);