3

ENV爲什麼我用32 webdriver2.8</p> <p>我使用硒(JAVA)硒

鉻點擊兩次到一個提交輸入點擊提交輸入。但我需要點擊兩次來激活提交操作。

輸入代碼:

<input type="submit" disabled="disabled" id="id_submit" name="submit" class="btn-txt" value="OK"> 

NOT WORK硒代碼:

if(submitButton.isEnabled()) { 
    new Actions(driver).moveToElement(submitButton).perform(); 
    submitButton.click(); // this sentence is executed. 
} 

WORKS

submitButton.click(); 
submitButton.click(); 

好,第一次點擊的功能似乎使按鈕獲得重點,第二次點擊功能主動提交操作。當我使用moveToElement首先聚焦按鈕時,點擊也不起作用。我可以確保按鈕已啓用。我想用硒來點擊按鈕,我不想點擊兩次。我該怎麼辦?有任何想法嗎?謝謝。

編輯

工程無論

JavascriptExecutor jse = (JavascriptExecutor) driver; 
jse.executeScript("document.getElementById('id_submit').focus();"); 
jse.executeScript("document.getElementById('id_submit').click();"); 

UPDATE

想象一下,我想輸入一個字符串,說 「abcdef123456」。然後執行send_keys。它看起來像 enter image description here並提交按鈕已啓用。在第一次點擊提交按鈕後。它看起來像enter image description here並提交按鈕獲得焦點。第二次點擊提交按鈕後,表單被提交併且頁面被重定向。我很困惑第點擊

+1

在HTML ...看看'殘疾人='disabled''你不能(也不應該)點擊的東西是無法與之交互。 – sircapsalot

+0

'new Actions(driver).moveToElement(submitButton).perform(); submitButton.click();'被執行。所以它應該被啓用。 –

+0

*點擊兩次*是硒還是硒溶液的缺陷? –

回答

2

你嘗試過用Expected Conditions類,

new WebDriverWait(driver,30).until(ExpectedConditions.elementToBeClickable(By.id("id_submit"))).click(); 
+0

我等10了,這對我不起作用。 –

+0

30不適合我,ethier。 –

+0

那麼'JavascriptExecutor jse =(JavascriptExecutor)驅動程序; (「document.getElementById('J_submit')。focus();」); (「document.getElementById('J_submit')。click();」);'適用於我。我不知道爲什麼。 –

0

它可以解決這樣的: driver.sendkeys( 「ABC1234」); (在文本框中輸入)

//顯式等待 WebDriverWait w = new WebDriverWait(driver,10);

w.until(ExpectedConditions.elementToBeClickable(By.id( 「按鈕」))); 或 w.until(ExpectedConditions.visibilityOf((WebElement)By.id(「Button」))); 。

driver.findElement(By.id( 「按鈕」))點擊();

+0

我沒有等待'elementToBeClickable' 30秒,這對我不起作用。它是可見的。所以不需要等待'可見性'。 –