Behat test browser does not scroll down to find element - selenium

When I run my behat test, it opens Firefox as expected. However it does not find for example a button because it doesn't scroll down in the page.
But when I quickly zoom out in the browser enough by pressing ctrl+-, then I can see that behat suddenly does scroll down and find the button that it needs to press.
I don't know what's the cause to this problem. Anyone can give a direction?
The error message:
On line:
And I press "Add to cart"
(Element is not clickable at point (407.6000061035156,
15.699996948242188). Other element would receive the click:
Command duration or timeout: 86 milliseconds Build info: version:
'2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17' System
info: host: 'LBNL03572', ip: '10.38.188.18', os.name: 'Windows 7',
os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_17' Session
ID: 948e4f65-f1bc-492b-9c6d-07735d09b59f Driver info:
org.openqa.selenium.firefox.FirefoxDriver Capabilities
[{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true,
cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox,
handlesAlerts=true, nativeEvents=false, webStorageEnabled=true,
rotatable=false, locationContextEnabled=true,
applicationCacheEnabled=true, takesScreenshot=true, version=44.0}])
Update:
I think it's because on top of the page there is a menu bar with position absolute/fixed on top with a height of 35px. I think that in the "normal" state, it scrolls down but the button itself is under the menu bar. So it can't click it, actually it tries to click on the menu bar div. And by accident when I zoom out the button is clickable or something.
Can I force it to scroll more or something?
Update 2:
I now use the function shared on https://gist.github.com/MKorostoff/c94824a467ffa53f4fa9
So before I press the button I scroll to it
And I scroll "edit-submit" into view
And I press "Add to cart"
Now it works because it scrolls down until the button appears on the bottom of the page. I think by default behat uses a page down like scroll method. So when it scrolls, step by step, the button would be on top.
But I don't consider this a good solution. Because this implies that every time I want to press a button I first need to add that scroll to line. There should be a way to automatically scroll correctly and take in to account the fixed positioned menu bar on top.

Related

Selenium 3.0.1 with safaridriver failing on waitForElementVisible()

Safari 10.0.1
macOS Sierra
When running Codeception command:
$I->waitForElementVisible(['css' => 'input[type=text][id=UserUsername]'], 30);
in an acceptance test in Safari with Selenium 3.0.1 I receive an error. The screenshot taken at failure clearly displays the element in question. The same test/command is successful in both Firefox and Chrome. The error:
Screenshot saved to /Applications/MAMP/htdocs/AutomatedTests/tests/_output/debug/FAILED1479307207.png
Unable to retrieve Selenium logs : The command 'GET /session/9BC56414-8934-4315-9293-B6E99720E318/log/types' is not implemented.
Command duration or timeout: 3 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'Cosettes-MacBook-Pro.local', ip: '10.0.1.75', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12602.2.14.0.5, cleanSession=true, platform=MAC, nativeEvents=true, locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 9BC56414-8934-4315-9293-B6E99720E318
Screenshot and page source were saved into '/Applications/MAMP/htdocs/AutomatedTests/tests/_output/' dir
ERROR
When I run the same test/command in Safari/Firefox/Chrome with Selenium 2.53.1 it finds the element with no problems.
Is there a known issue with this type of locator I'm not finding when going through the forums? Anyone have a suggestion for how to make this work?
Update 12-01-16: This now seems to be more of an issue with waitForElementVisible() command than the Locator. If I change the command to $I->waitForElement(['css' => 'input[type=text][id=UserUsername]'], 30); the test successfully moves forward till the next waitForElementVisible() command.
People say visibility checks are broken in the release version of Safari 10. You can try Safari Technology Preview, and if your issue is still there, we can conclude it's some other issue, not the broken visibility checks. If your issue is gone, it'll be not exactly your users' experience, but better than nothing anyways. Also you can try implementing your own visibility checks as a workaround using some script on the browser's side (e.g. this function looks good enough).
To run your tests in Safari Technology Preview, add
'safari.options': { technologyPreview: true }
to the capabilities.
See also my other answer on this subject.

Elements are not get in IE Browser

Elements are not get in IE Browser. i am using IE 11 Browser. While I am run my code then Error is displaying in my consol as Started InternetExplorerDriver server (32-bit) 2.47.0.0
Listening on port 20577
Error show := org.openqa.selenium.NoSuchElementException: Unable to find element with id == Id_user_name_id (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.17 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'VDJSDEV2-PC', ip: '172.16.1.220', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:20577/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 8bd16d35-c13d-46f7-b6cf-f9a7ddd54dda
*** Element info: {Using=id, value=Id_user_name_id}
And I am using these Jar files
selenium-server-standalone-2.47.1.jar
selenium-ie-driver-2.47.0.jar
selenium-java-2.47.1-srcs.jar
selenium-java-2.47.1.jar
IEDriverServer_Win32_2.47.0
I found the same problem, and my solution is:
Modified IE setting to display both secure and non secure contents.
Set the Protected Mode settings for each zone to be the same value, the value can be on or off, as long as it is the same for every zone (I checked "Enable Protected Mode" all).
Way to set protected mode: choose "Internet Options..." from the Tools menu -> click on the Security tab. For each zone (Internet/Local Internet/Trusted Web Sites/Restricted Sites), check the check box at the bottom of the tab labeled "Enable Protected Mode".
Restart your IE browser.
It works on me, hope it can help you too.
Some suggestion which may help.
Check the element id is unique in the page and actually exist; can you post the html page ( just the element and its parent parent if possible)
Increase the browser capabilities timeout to double the existing one
before you search for the element by id
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Try with different Driver (Firefox or Chrome) and see if the problem persist
Try to search the element by selector; if you post the html page, I can help in sending some suggestion
Cheers
Alan Mehio
London

How do you select a link from a drop down window with PHPUnit & Selenium

Hi I am beginning to start automating some tests. I am trying to verify that certain submenu options exist when you hover over the dropdown menu. But I get an error returned from PHPUnit:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 16 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'WIN-5FCJ9IIGCSP', ip: '192.168.31.128', os.name: 'Windows Server 2008 R2',
os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 9fad5b24-2a1e-472d-bb36-b8914b3a92c2
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=27.0.1}]
I have been searching the web and would appreciate any help
Thanks
Conor
Before you search for the element(dropdown)
Try to put a:
sleep(3); // This will make it sleep for 3seconds
Or waitForElementPresent could work aswell.
And see what you get. Selenium might think that the page is already loaded and tries to find the element which isn't loaded yet: Element is not currently visible
I'm also at the very beginning of selenium, but here is a solution I wrote for clicking a dropdown element
for($tick=0 ; $tick<5 ; $tick++){
$this->moveto($this->byCssSelector('#dropDown'));
}
$this->byLinkText("Settings")->click();
If I didn't wrap the moveto() with the for loop, it would just hover momentarily and didn't work, so the ticking kept it hovered.
I suggest you to use the waitUntil() function and check when your element is displayed()

Behat/Mink - Test failing after search action taken

I am working on writing Behat tests for an old bojankity system written in PHP. It seems to work for a number of test cases. However I am running into a strange problem.
I have Behat logging in and navigating to the search form page. Then it fills out the form by selecting a few drop-downs and filling in a text field. And then clicking the search button (keeping in mind that the button and some of the drop-downs have some JS actions attached to them). All of those actions pass, but on the next step after I run 'Then I press "Search"' I get the following error/message:
Then I wait five seconds # FeatureContext::iWaitFiveSeconds()
Modal dialog present
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.5.0-31-generic', java.version: '1.6.0_43'
Session ID: 13badfa6-9847-4db4-901f-fcfde797df92
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=21.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
This is running through the Selenium 2 driver. The context function mentioned here is just a JS wait call. I use it and variations on it in several places. The same thing happens when I do other things at this point instead of waiting, such as checking for certain text on the page.
Any idea what might be going on? By the way, this is for an internal web app, so there are no URLs I can give out. I should also add that I am running this on Ubuntu 12.10 with PHP 5.3.
Thanks!
This could be caused due to an AJAX call messing with the flow of the test. make sure you give enough time for your AJAX requests to complete in the previous scenarios.
Best

selenium click and sendkeys fails at random on IE when using remotewebdriver

I am using remote webdriver to drive an IE browser on a remote VM [ this is part of a grid setup]
I noticed that the click and sendkey events fails at random that is the session ends and the browser quits .This happens at different parts of the script it is not secluded to one area and occurs only when executing click and sendkey events .
Looking at the logs its looks like the event actually fired but did nothing and so when it moves to the next line it exits because it could not find the element.
I am using IE8 and the browser zoom is set to 100% . I have tried using JavaScriptExecutor with Jqueryselectors and got a javascript Exception hence I am forced to use click and send keys.
is anyone facing the a similar issue
I was having similar issues with Remote Web driver running on an iPhone. It seems that the Remote Web driver doesn't support jQuery touch events, meaning that the JQuery is looking for a given number of touch events, ex. tap, touchstart, swipe etc. but Selenium is not triggering any of them when you call click. I resorted to using the following Javascript:
window.jQuery(document.elementFromPoint(198,216)).trigger('touchstart');
You can use driver.findElement(By.id(id)).getLocation() to get the location of the element you want to click.
I did however get an exception when I executed the Javascript:
org.openqa.selenium.WebDriverException: 'undefined' is not an object
Command duration or timeout: 530 milliseconds
Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.5', java.version: '1.6.0_37'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:366)
at com.alea.qa.sample.CustomTouchAction.executeScript(CustomTouchAction.java:108)
at com.alea.qa.sample.CustomTouchAction.Touchstart(CustomTouchAction.java:76)
at com.alea.qa.sample.anotherRun.main(anotherRun.java:34)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: 'undefined' is not an object
Build info: version: '2.2.1', revision: '16551', time: '2012-04-11 21:42:35'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.5', java.version: '1.6.0_37'
Driver info: driver.version: unknown
But it still managed to click on the element.
Have a look at this question and its (currently first and only) answer, by user Slanec. It sounds similar. In short, try resizing your browser window. Elements near the edges can be inaccessible to Selenium drivers.