0

As the following code shows, clicking the element by the WebElement.click() method works, while JavascriptExecutor.executeScript fails ( works in most situaitons ).

WebElement e = driver.findElement(By.xpath("......."));//some kind of checkbox
e.click(); //works fine.
((JavascriptExecutor) aw.driver).executeScript("arguments[0].click();",e); 
//executes with no exception, but the element is not selected.

The page's source code is too complex to paste here, sorry.
Any clue or tip for debugging this problem?

The element's html code, It's a extjs-style checkbox:
<td class="x-grid3-hd x-grid3-cell x-grid3-td-checker x-grid3-cell-first " style="width: 20px;"> <div class="x-grid3-hd-inner x-grid3-hd-checker" id="ext-gen108" unselectable="on" _nodup="30805"> <div class="x-grid3-hd-checker" _nodup="30805" /> </div></td>

I have tried click each of td, td/div , td/div/div elements , getting same result: WebElement.click() works, JavascriptExecutor.executeScript fails(No exception, but the checkbox is not checked).

2 Answers 2

1

I would not assume the JavaScriptExecutor failed to execute your Script first, but see if the Script is working as expected.

Try to set break point at "e.click();" and then start debugging, after that try to run your Script (which is "arguments[0].click();" in your case) in browser console and see what happened.

If you have confirmed the script is good, then try to put break point at your executeScript and make sure that line of code have been run successfully.

Sign up to request clarification or add additional context in comments.

Comments

0

Instead use document.evaluate() for JavaScript executor method.something like this: executeScript("document.evaluate( \"" ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.click()");

1 Comment

It seems that IE doesn't support document.evaluate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.