I have selenium test running in a remote server in headless mode using chrome driver. Following step tries to click on a button but the button doesn't get clicked.
Below test step tries to click the element:
action.moveToElement(element).click().build().perform();
Here is the html of the button:
<button class="icon-btn" data-uk-tooltip="" data-ember-action="90"><i class="us -icon-hover us-icon-plus-circle"></i></button>
Any insight why in headless mode the button is not clicked by above test step? would appreciate any ideas.
Let's try with this, it will work :
WebDriver driver = new HtmlUnitDriver();
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
I suspect this to be an actual Selenium issue. But I manage to solve and stabilize my tests. See Using Selenium, is there another, more reliable, way to use click command on an element in Headless Chrome?
Related
I have SPA (single page application) written using Backbone + jQuery and some automation tests (Selenium) and when some of the tests are running they start failing because of a DIV element disappears itself. It disappears just after the last AJAX call is finished.
I cannot find the reasons of disappearing. Does probably someone know what could it be?
The issue is only under Chrome launched by Selenium.
I tried to refresh the page in Selenium Chrome - The issue is still here.
I tried to disable all installed plugins (including Selenium plugin) in Selenium Chrome. - The issue is still here.
I tried to update Chrome. - The issue is still here.
I tried to update Selenium. - The issue is still here.
A few interesting moments:
When I mouse over the place where DIV should be - it SHOWS!
When I try to check the height of the DIV with $('.container').height() - it SHOWS!
I tried to use Chrome launched by myself under Incognito mode. - No issue.
It looks like Chrome forgets to re-render the DOM or that element.
I am running automated (python) selenium tests on a chrome browser, and sometimes when a page is reloaded a popup appears on the screeen:
Is it possible to configure the chrome selenium browser in such a way, that this popup does not appear? If so, how to do that? Or are there other ways to supress this popup? Or to accept it?
This popup with text as Reload site? Changes you made may not be saved is the implementation of onbeforeunload property of WindowEventHandlers
onbeforeunload
The onbeforeunload property of the WindowEventHandlers mixin is the EventHandler for processing beforeunload events. These events fire when a window is about to unload its resources. At this point, the document is still visible and the event is still cancelable.
Solution
There are different strategies available to handle this popup.
Chrome solution: Using --disable-popup-blocking through ChromeOptions():
from selenium import webdriver
options.add_argument("--disable-popup-blocking")
driver=webdriver.Chrome(chrome_options=options, executable_path=/path/to/chromedriver')
Firefox solution: Using dom.disable_beforeunload through FirefoxProfile():
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.disable_beforeunload", True)
driver = webdriver.Firefox(firefox_profile = profile)
Cross Browser solution: As a Cross Browser solution, you can disable this dialog invoking the executeScript() to set window.onbeforeunload as function() {}; and you can use the following solution:
driver.execute_script("window.onbeforeunload = function() {};")
JQuery based solution:
$I->executeJS( "window.onbeforeunload = null" );
You can find a relevant discussion in How to handle below Internet Explorer popup “Are you sure you want to leave this page?” through Selenium
I know this doesn't answer the suppression part of the question, but..
Try this piece of code for accepting the popup:
driver.SwitchTo().Alert().Accept();
I'm working on a Rails App and we've started using capybara for our functional tests. Our tech lead has had us writing tests and using Selenium, but then wants to switch to webkit for final testing prior to a deploy.
I've written a set of functional tests that mimic a user clicking through a tree menu, clicking a button to open a modal, clicking a few buttons within the modal (eventually opening a form), and then submitting the button.
These tests pass with flying colors in selenium. Firefox pops open and it whips through the complete test suite.
Switch over to webkit, and there is a consistent point at which the tests fail. When the modal is open, and it attempts to "click" a button to switch from a "Interaction History Form" to a "New Interaction Form"
The following is a list of the various command attempts I've done at "clicking" the New Interaction Button.
With selenium, this is simple and works:
click_button('New Interaction')
and some of these work in selenium, some don't, but none of them work with WebKit.
# page.execute_script %Q{ $('.btn.btn-default.toggle-interaction').css('display, inline-block'); }
# page.execute_script %Q{ $('.fa.fa-plus').click(); }
# page.find('.btn.btn-default.toggle-interaction').click
# within('#interaction-history') { find_button('New Interaction').click }
click_button('New Interaction')
# find_button('New Interaction').trigger('click')
# within(".btn.toggle-interaction") do
# click_on("New Interaction")
# end
# find('.btn.toggle-interaction').trigger('click')
# find_button('New Interaction').click
# within('.insight-wrapper') { find_button('New Interaction').click }
We decided to try and use the capybara-screenshot gem, so that we could get a snapshot of the HTML and the "rendered" page during headless test failure.
I don't have a good photo editing app so I can't scrub out the protected info to post a screenshot, but in the saved snapshots (and saved html files), the images look right.
One idiosyncrasy in the screenshots is the location of the mouse cursor in the screenshot. Sometimes it's on the button it attempted to click, and other's it isn't.
One other idea we entertained is the idea that it could be a timing issue, and that it's trying to click the button before it has been successfully rendered. To mitigate that we added a pause method that forced the tests to wait. That didn't resolve the issue.
We looked at switching to a headless selenium using poltergeist/phantomJS, but a lot of the comments on that route seem to indicate a higher quantity of "random JS errors" than with webkit. Would there be an alternative headless selenium solution that could be worth investigating?
Thank you for your time and help,
Alex
I'm using selenium IDE (currently available only on firefox) to do some automated testing of a site I'm coding. When selenium navigates to, a form filling page, and fills in the info - a 'window.alert()' is called by a button.
When using selenium my set of commands look like this:
open /
clickAndWait document.form1.Action[1]
select stuff
type stuff
etc, etc
click name=myPreview
When I click through recording this the first time, it works no problem. When I rerun the script window.alert and alert don't work from the console or anything. I've debugged it, and its not working.
When a window.alert() is called as part of a selenium script (I'm talking at least in the IDE), it is called even though a user watching does not see an alert pop up. According to the documentation:
Under Selenium, JavaScript alerts will NOT pop up a visible alert
dialog.
Selenium does NOT support JavaScript alerts that are generated in a
page's onload() event handler. In this case a visible dialog WILL be
generated and Selenium will hang until someone manually clicks OK.
Both assertAlert and verifyAlert are both based off getAlert(), all of which do the alert 'stuff' in the background. So try adding these functions to ensure that the alert is working, run the script, and then check to see if it works.
A note: this only works if you ensure the test fails before you put in the alert (basic idea of testing, fail first - make test pass).
I'm using this code to click on an element: #driver.find_element(:id, "test").click and it works well when I run script on FF16 with Selenium Ruby Webdriver (selenium-webdriver-2.26.0.gem).
However, when trying to run script in IE9 browser (using IE driver: IEDriverServer.exe), no error occurs, but Click event does not work, Selenium seems to ignore this line of code and go to next lines of code.
Note that this issue does NOT happen when I tried to click on many other elements on my application (ex: button, link), it only happens with some elements I want to click.
Please help guide me how to resolve for Selenium to fire Click in IE9 browser. Thanks much.
Try click using JavaScriptExecutor or Click after moving to the element. refer below C# code
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", element);
or
Actions action = new Actions(driver);
action.MoveToElement(element).Click().Build().Perform();
where element is IWebElement instance of element to click