Webdriver and Popups in HtmlUnitDriver

I'm currently trying to execute a JavaScript popup using the webdriver HtmlUnitDriver and this is creating a weird outcome.

The same line of code works fine with FirefoxDriver , but as soon as it switches to HtmlUnitDriver, it stops working. The simple code I use is here:

 Alert alert = driver.switchTo().alert(); alert.accept(); 

Is HtmlUnitDriver capable of handling Java pop-ups, or is it an HtmlUnitDriver bounding point.

this is a Javascript Confirm popup. We tried to use firefox properties using HTMLUnitDriver by doing the following:

 driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3); 

It was not successful.

The question is, should JavaScript for HTMLUnitDriver be enabled to interact with the Confirm popup? If YES, does anyone know how we can enable this?

 driver = new HtmlUnitDriver(capabilities); 

does not seem to work and is not recognized.

Any help would be greatly appreciated. Greetings

+4
source share
1 answer

This seems to be a long issue https://code.google.com/p/selenium/issues/detail?id=1105

I used the JavaScript workaround for the confirmation popup. Here is an example in Python:

 self.driver = WebDriver( command_executor='http://localhost:4444/wd/hub', desired_capabilities=DesiredCapabilities.HTMLUNIT) self.driver.execute_script("window.confirm = function(msg) {return true;};") self.find_element_by_id('mybutton').click() 

Override the confirm () function before you use it and return true for Accept. Then you trigger the click event. Change it to false for Cancel.

Pretty neat. I found this somewhere else in StackOverflow, but can't remember where.

+4
source

Source: https://habr.com/ru/post/1390668/


All Articles