2017-07-18 143 views
-1

我正在運行腳本使用寧靜jbehave。我需要點擊繼續按鈕。在這裏,我通過dynamic xpath來識別它。但它沒有響應按鈕點擊不工作在硒webdriver

這裏是網頁元素

<input type= "button" class="bin-large" onclick="continueperson(document.getElementById('controlTodisplay').value);" value="continue">==$0

我已經確定了它下面

Xpath=//input[@value='continue'] 

並進行點擊操作。

任何人都可以幫助我!

+0

您是否收到錯誤?或者它只是不工作?檢查是否有任何其他輸入值爲「繼續」 –

+0

如果它只是不工作,按鈕周圍可能有一個邊緣。 WebDriver將單擊元素的左上角。因此,如果按鈕外側有邊緣,則駕駛員可能會點擊該按鈕而不是實際的按鈕。 – stewartm

回答

1

事實上,大多數情況下,無法點擊按鈕的問題與您拼錯代碼無關,如果頁面未完全加載,請嘗試執行「A」模式,如果繼續執行錯誤做 「B」

A模式: driver.findElement(By.xpath("//input[@value='continue']"));

B型: WebDriverWait wait =new WebDriverWait (driver,10); wait.until(expectedconditions.elementtobeclickable(By.xpath("//input[@value='continue']")); driver.findElement(By.xpath("//input[@value='continue']"))

+0

是的,我已經嘗試過,但最後它的環境問題我們的代碼是正確的,非常感謝您的幫助 – Siva

1

嘗試以下任一提到代碼,點擊按鈕。

在點擊按鈕之前,請提供wait的幾秒鐘,以便您的驅動程序能夠找到webelement。

等待,我使用explicit wait方法。

WebDriverWait wait = new WebDriverWait(driver, 5); // wait for 5 seconds 
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//input[@value='continue'][@type='button']")))); 
driver.findElement(By.xpath("//input[@value='continue'][@type='button']")).click(); 

OR

嘗試點擊使用java-script executor方法按鈕。

WebElement button = driver.findElement(By.xpath("//input[@value='continue'][@type='button']")); 
((JavascriptExecutor) driver).executeScript("arguments[0].click();", button); 
+0

你試過這段代碼嗎? –

+0

請將此答案標記爲「Accepted」,如果它適合您。 –