2016-11-01 6 views
-1

.click()で実装されたセレンのクリック機能は、webdriver waitsleepのメソッドを含み、アクションでも使用されます。それらのどれも安定して動作しません。つまり、時には動作します。私はselenium-server-standalone-2.53.0.jarを使用していますセレンのクリックは、Javaスクリプトのエグゼキュータの代わりに動作しません。

ほとんどの場合、以下のようにJavascript executorを使用して回避することができました。

JavascriptExecutor executor = (JavascriptExecutor) driver; 
executor.executeScript("arguments[0].click();", element); 

私はJavaスクリプトエグゼキュータが推奨されていないことを多くのウェブサイトを読んで任意の一つが、このためのより良い方法やJavaスクリプトの代替を提案することができます。

これ以上の説明がない場合は、通常、Javaスクリプト実行者のclick()をクリックする必要があります。

ありがとうございます。

+0

動作しない場合は例外がスローされますか? – Sai

+0

@Sai例外はスローではなく、単にクリック操作をして次のステップに移動しますが、実際にはボタンをクリックしません。 – mmk

+0

どのようなタイプの同期を使用していますか?最大待ち時間は何ですか? – Sai

答えて

0
//where driver is an instance of WebDriver that you have initialized and now displays the web page of interest 
//and where elementToBeClicked is an instance of class By, e.g. By elementToBeClicked = By.id("myButton"); 
Wait<WebDriver> wait_element = new WebDriverWait(driver, 40); 
WebElement aLinkOrButton = wait_element.until(ExpectedConditions.elementToBeClickable(elementToBeClicked)); 
aLinkOrButton.click(); 
+0

も動作しません。 'Wait wait_element = new WebDriverWait(driver、40); WebElement aLinkOrButton = wait_element.until(ExpectedConditions.elementToBeClickable(elementToBeClicked)); aLinkOrButton.click(); ' JavaScriptExecutor以外の方法があります – mmk

0

それが動作しない場合は、私を許して... :)

は "visibilityOfElementLocated" を使用してみてください。

Wait<WebDriver> wait_element = new WebDriverWait(driver, 40); 
WebElement aLinkOrButton =  wait_element.until(ExpectedConditions.visibilityOfElementLocated(elementToBeClicked)); 
aLinkOrButton.click(); 
関連する問題