简体   繁体   中英

InvocationTargetException thrown with java/selenium webdriver action class

I'm using IE driver with java. I've done this fine in c# but trying java and hitting a snag. I instantiate the driver with a singleton pattern at the class level and then begin a junit test with the @Test. I separated the finding of the element out from the action and the finding of the element works great identifying the element with id=69 and the hexidecimal code the browser auto-assigns it. So far so good.

Then I take that variable for the WebElement and pass it into the action.click(element); At this point an InvocationTargetException is thrown with a null. Researching I have found where the driver null is causing an issue, but like I said driver is not null and has an element variable that populates accurately.

I'm wondering if there is something wrong with the selenium reference or something behind the scenes that may be throwing null when trying to utilize the library. Any ideas where I might look to get this to work? This is technically a java.lang.reflect exception and not a selenium specific exception, which if it was a null variable I would expect it to throw a selenium exception.

Any pointers or thoughts would be appreciated.

I found the answer. The actions class was unbound to the driver. So I could use the driver all I wanted, but the actions initiation couldn't find the browser to execute the actions on. I had a sub-class named Action that I was working with which confused me with the "Actions" class that was selenium.

Oops, but if anyone runs into that InvocationTargetException with a null value while trying to utilize selenium, be sure that each selenium class is properly instantiated and associated with the active driver instance.

我使用了下面对我有用的代码。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM