Selenium 2.0b3 IE WebDriver, Click not firing

后端 未结 18 1960
我寻月下人不归
我寻月下人不归 2020-11-29 02:33

When using the IE driver with IE9, occasionally the Click method will only select a button, it wont do the action of the Click(). Note this only happens occasionally, so i d

18条回答
  •  无人及你
    2020-11-29 03:02

    I resolved problem whith .click() next way. I used JS and executeScript(JS, WebElement el) instead of .click().
    Example:

    protected void clickForIE(WebElement element){  
            ((JavascriptExecutor)wd).executeScript("var tmp = arguments[0];
              tmp.click()", element);  
        }
    

    But after using this method we should wait while page loading. And that's why I used next method:

    protected synchronized void pageWaitLoad() {  
            String str = null;
            try {
                str = (String)((JavascriptExecutor)wd).executeScript("return document.readyState");
            }
            catch (Exception e) {
    // it's need when JS isn't worked
                pageWaitLoad();
                return;
            }
            System.out.println("ttt " + str);
            while(!str.equals("complete")){
                try {
                    Thread.currentThread().sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                str = (String)((JavascriptExecutor)wd).executeScript("return document.readyState");
            }
        }
    

    You must call pageWaitLoad() every time after clickForIE().

提交回复
热议问题