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

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.

Related

Failed: sendKeysToActiveElement error while invoking sendKeys to ENTER and other keystrokes using ChromeDriver Chrome with Protractor

My Protractor tests that use sendKeys to press Enter or Tab failed today after I was auto-updated to Chrome 76.
This worked find yesterday on Chrome 75.
This is the code that used to work:
browser.actions().sendKeys(protractor.Key.TAB).perform();
The error message is
Failed: sendKeysToActiveElement
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'DESKTOP-6JGLC4V', ip: '192.168.0.5', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_221'
Driver info: driver.version: unknown
Our Angular application has drop-down menus where you have to click outside of the drop-down or press the Tab key to close it. So I'm not sending the key stroke to an input element. I've tried $('body').sendKeys(protractor.Key.TAB); but that doesn't seem to work.
This error message...
Failed: sendKeysToActiveElement
...implies that the ChromeDriver was unable to invoke sendKeys() to the ActiveElement.
This issue started to surface when ChromeDriver / Chrome switched over to W3C support.
#AutomatedTester in the discussion UnsupportedOperationError: sendKeysToActiveElement with sendkeys mentions, this may be an issue within the Actions class within the Client bindings.
There should be a little shim in the bindings that make sure the same functionality is given on older commands that have been removed. This has been implemented in the core selenium binding.
The Python example:
def send_keys(self, *keys_to_send):
"""
Sends keys to current focused element.
:Args:
- keys_to_send: The keys to send. Modifier keys constants can be found in the
'Keys' class.
"""
typing = keys_to_typing(keys_to_send)
if self._driver.w3c:
for key in typing:
self.key_down(key)
self.key_up(key)
else:
self._actions.append(lambda: self._driver.execute(
Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {'value': typing}))
return self
def send_keys_to_element(self, element, *keys_to_send):
"""
Sends keys to an element.
:Args:
- element: The element to send keys.
- keys_to_send: The keys to send. Modifier keys constants can be found in the
'Keys' class.
"""
self.click(element)
self.send_keys(*keys_to_send)
return self
Solution
#barancev have already merged the required changes through the commit Renaming back 'py' directory, use of 'legacy_create_init' argument and this issue would get completely resolved with the next release of ChromeDriver v77.0 / Chrome v77.0.
The good news is ChromeDriver v77.0 is already released containing the following fixes. From the Release Notes of ChromeDriver v77.0:
Resolved issue 2975: Webdriver Actions for keys (CONTROL, SHIFT etc..) not working in ChromeDriver 75.0.3770.8 [Pri-2]
Resolved issue 2981: Chromedriver in W3C mode loses mouse state between Actions API calls [Pri-2]
Outro
Protractor.Key.Enter is not working in ChromeDriver v75.0.3770.8
Upgraded to chromeDriver 77 and still running into the same issue as mentioned above.
await elem.sendKeys(protractor.Key.TAB); also tried: await browser.actions().sendKeys(protractor.Key.TAB).perform();
`- Failed: sendKeysToActiveElement
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'GC02XYZ...', ip: 'fe80:xyz...', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '11.0.1'
Driver info: driver.version: unknown`
`chromeDriver -v
ChromeDriver 77.0.3865.40`
When using chrome 74+ please add the below at configuration.js file
exports.config = {
seleniumAddress : 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
capabilities:{
'browserName': 'chrome',
'goog:chromeOptions': {
w3c: false
}
}
};
Notes:
refer the this link
https://github.com/angular/protractor/issues/5274#issuecomment-522258213

Selenium - Remote Control - Unable to create new service: ChromeDriverService

When I start the selenium test with gird (Remote control), I see this ERROR on log. The browser is not able to open. I did check and tried the following things:
Stop and start both hub and node. I use the default commands to start hub and node. From command prompt, I see that the node was registered successfully and ready to use
Clean Eclipse Project at Project>Clean
Restart my PC
Disconnect VPN
Use latest selenium standalone 3.6; chromedriver.exe
Check the path to chromedriver.exe
Use my PC as hub and another PC as node
Please note that this issue only happen if I run the test with grid (remote control). The test can run normally locally.
2017-10-20 15:23:37,805 ERROR [Log] Class Utils | Method OpenBrowser | Exception desc : Unable to create new service: ChromeDriverService
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'MY-PC', ip: 'xx.xxx.xxx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: unknown
Command duration or timeout: 319 milliseconds
Please give me advice in this case. Thanks!

Scripts for Selenium Chrome and htmlUnit

I have some Java scripts for Chrome browser and now I want to run the scripts in htmlUnit. I think the scripts are the same for both, but I got some error when running in htmlUnit? why? So basically which actions (click()? isDisplayed()? etc.) only in Browser test but not in headless tests? and general documents about this difference? Thanks
######### Seems css may have problem here but work OK in Chrome ##############
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Returned node was not an HTML element For documentation on this error,
please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05
22:01:35' System info: host: 'FGS-CIT-2758', ip: '192.168.200.201',
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.8.0_40' Driver info: driver.version: HtmlUnitDriver at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByCssSelector(HtmlUnitDriver.java:1002)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:426) at
org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1648)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1302)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1644)
at
org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:550)
at com.ATIP400Suite.CH_ATIP40.mainCheck(CH_ATIP40.java:461) at
com.ATIP400Suite.CH_ATIP40.main(CH_ATIP40.java:58)
Line461 =
driver.findElement(By.cssSelector("span.icon-meter.enlargeIcon")).isDisplayed()
Did you enable javascript in HtmlUnitDriver?
If yes, before click check ExpectedConditions:
presenceOfElementLocated (if you are not sure that an element is present on the DOM)
elementToBeClickable
good luck...

Selenium 2.47 doesn't work with Firefox v31

I am using selenium 2.47 with Firefox v31. With this simple implementation:
public void navigateToHomePage() throws Throwable {
System.out.println("Navigate to Home");
driver = new FirefoxDriver();
driver.quit();
}
I got this error:
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
Build info: version: '2.47.0', revision: '0e4837e', time: '2015-07-29 22:49:49'
System info: host: 'ok-ThinkPad-SL500', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_79'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.internal.SocketLock.lock(SocketLock.java:99)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:90)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:276)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:223)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:212)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at cucumber.features.StepDefinitions.navigateToHomePage(StepDefinitions.java:24)
at ✽.Given I navigate to the home site(/home/ok/workspace/CucumberPOC/src/cucumber/features/UserRegistry.feature:6)
I don't know what is it??
This SocketLock error happens when Firefox tries to bind to port 7054 and fails because another instance already has that port locked.
An immediate solution is make sure you have NO Firefox tasks or process running in the background before launching a new driver. Kill them all and try launching again.
In the long run, you can avoid these issues by creating a new profile, change the port preferences to avoid locks, and then launch the driver using that profile. A short example:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, 7046)
driver = new FirefoxDriver(profile);
Unfortunately, when I was looking up the Java terms, I found that this feature was broken in Java's driver once, then it was fixed and then it broke in a later update, so even if you implement the solution I gave you, you may still get these errors in 2.47.
The fix was released in version 2.43.1, so if you don't need the newer versions for another issue/feature, you can try rolling back to a point where you can set a port preference successfully.
Not required reading: Some more technical details of the issue are in this pull request.

getting exeception while using chrome browser in selenium project

I am using chrome browser in selenium project.
Here is the user agent string that I am using:
System.setProperty("webdriver.chrome.driver","C:\\users\\..\\chromedriver.exe");
driver = new ChromeDriver();
What happens IF I run the script:
It open the chrome browser and after some time it close it and giving error:
org.openqa.selenium.WebDriverException: unknown error: unable to
discover open pages (Driver info: chromedriver=2.2,platform=Windows
NT 6.1 x86) (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 26.83 seconds Build info:
version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'QAVM-9', ip: '27.101.1.26', os.name: 'Windows 7',
os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45' Driver
info: org.openqa.selenium.chrome.ChromeDriver at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at
org.openqa.selenium.chrome.ChromeDriver.startSession(ChromeDriver.java:182)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:161)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:150)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:139)
Please help me, It completely stop the execution.
Let me know in case need any other information.
I would suggest you to update your chrome driver since your version is 2.2 and the latest is 2.9. It might be possible that your existing chrome driver might not be supporting your chrome browser if the browser is of latest version.
Chrome driver versions are here
Also check the release notes here. Each chromedriver mentions which chrome browser versions
it supports.
Here's what I did to get rid of that error (
unknown error: unable to discover open pages
)
In your protractor config file, add the following:
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox']
}
},
The most important line there is the --no-sandbox; adding that line somehow gets rid of that error.
I am not exactly sure why it works but it's a workaround I found while digging around online.