What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?

1,041 views
Skip to first unread message

David

unread,
Jul 24, 2012, 6:27:09 PM7/24/12
to webdriver
Just wanted to check what types of javascript code won't work when
executed from SafariDriver with the js executor? Relative to other
browser drivers that is.

I've come across issues trying to click the login buttons of
integrated services like Facebook, Picasa, Flickr, etc., particularly
Facebook for the example on hand.

In Selenium RC, our workaround was to manually open the URLs to those
login pages (in a new window) to simulate clicking the login button
and then proceed from there. I would prefer not to have to deal with
URL alternatives in WebDriver.

Taking workaround example for mouseover issue

http://code.google.com/p/selenium/issues/detail?id=2067 (comment #60),

I adapted version for mouse click / onclick event. Example Python
code:

clickScript = "if(document.createEvent){var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject) { arguments[0].fireEvent('onclick');}"

driver.execute_script(clickScript,driver.find_element_by_xpath("//
div[@id='fbLoginContainer']"))

this works as workaround for IE, but fails for Safari. Does nothing,
no errors returned.

Also works for Chrome, assume to work for Firefox (didn't test yet).

Are mouse events from DOM/javascript not supported by SafariDriver
(yet)? Not talking about interactions API, but just mouse manipulation
from direct javascript.

Per the referenced issue above, I didn't verify myself, but my
colleague said the mouseover workaround worked for Safari. Wonder why
mouse click doesn't. In case it helps excerpt of SafariDriver console
logs:

[146.046s] [safaridriver.inject.Tab.TOP] [ujzs3bkb1ljj] Executing
{"id":"rhnodkjop3p6","name":"findElement","parameters":
{"using":"xpath","value":"//div[@id='fbLoginContainer']"}}
safari-extension://org.openqa.selenium-UASV6TAR75/646e2b5b/injected.js:
9283 [146.047s] [safaridriver.inject.Tab.TOP] [ujzs3bkb1ljj] Sending
response
command: {"id":"rhnodkjop3p6","name":"findElement","parameters":
{"using":"xpath","value":"//div[@id='fbLoginContainer']"}}
response: {"status":0,"value":{"ELEMENT":":wdc:1343166330858"}}
safari-extension://org.openqa.selenium-UASV6TAR75/646e2b5b/injected.js:
9283 [146.077s] [safaridriver.inject.Tab.TOP] [ujzs3bkb1ljj] Executing
{"id":"jqhymtzd3vg","name":"executeScript","parameters":{"args":
[{"ELEMENT":":wdc:1343166330858"}],"script":"if(document.createEvent)
{var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}
safari-extension://org.openqa.selenium-UASV6TAR75/646e2b5b/injected.js:
9283 [146.078s] [safaridriver.inject.PageScript] Sending message:
{"origin":1,"type":"command","command":
{"id":"jqhymtzd3vg","name":"executeScript","parameters":{"args":
[{"ENCODED_ELEMENT":"/HTML/BODY/DIV[5]/DIV/DIV/DIV[2]/DIV[2]/SPAN/
DIV"}],"script":"if(document.createEvent){var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}}
all.js:44Received message of type object from http://www.treat.com,
expected a string
page.js:6009 [ 61.531s] [safaridriver.inject.page] Sending
executeScript response: {"origin":
2,"type":"response","id":"jqhymtzd3vg","response":{"status":
0,"value":null}}
all.js:44Received message of type object from http://www.treat.com,
expected a string
safari-extension://org.openqa.selenium-UASV6TAR75/646e2b5b/injected.js:
9283 [146.088s] [safaridriver.inject.Tab.TOP] [ujzs3bkb1ljj] Sending
response
command: {"id":"jqhymtzd3vg","name":"executeScript","parameters":
{"args":[{"ENCODED_ELEMENT":"/HTML/BODY/DIV[5]/DIV/DIV/DIV[2]/DIV[2]/
SPAN/DIV"}],"script":"if(document.createEvent){var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}
response: {"status":0,"value":null}

Easy to reproduce. Go to www.Treat.com, and attempt to click the
Facebook login button "//div[@id='fbLoginContainer']" using click
method or javascript. For SafariDriver, I was using it with remote web
driver in Python, release 2.24.1.

Peter Gale

unread,
Jul 24, 2012, 6:35:54 PM7/24/12
to webd...@googlegroups.com
I can't see that WebDriver would prevent any javascript from working ... it just blindy passes the text you create to the browser for execution, even allowing invalid javascript or text which will cause the program to "hang" (perhaps waiting for a response) in my experience.

Of course, the same javascript might potentially not work for all browsers, particularly if you accidentally have browser specific XPath, perhaps.

It's a bit hard to tell, but I think your error message may refer to the WebDriver findElement command rather than the javascript call itself. I'd suggest doing your findElement calls on a line of their own and then passing a reference to the object returned so that i is clearer where the problem lies.


> Date: Tue, 24 Jul 2012 15:27:09 -0700
> Subject: [webdriver] What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> From: mang...@gmail.com
> To: webd...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

David

unread,
Jul 24, 2012, 7:49:15 PM7/24/12
to webdriver
Ok, I separated it out as

btn = driver.find_element_by_xpath("//div[@id='fbLoginContainer']")
driver.execute_script(clickScript,btn)

and get this in the SafariDriver console logs below. Seems similar as
before. Is the return message about expecting string by the site under
test? Which isn't clear what the issue is.

[265.163s] [safaridriver.inject.Tab.TOP] [crkc5ck3dll2] Executing
{"id":"fnqqzctyyozq","name":"findElement","parameters":
{"using":"xpath","value":"//div[@id='fbLoginContainer']"}}
safari-extension://org.openqa.selenium-UASV6TAR75/f0a7decd/injected.js:
9283 [265.165s] [safaridriver.inject.Tab.TOP] [crkc5ck3dll2] Sending
response
command: {"id":"fnqqzctyyozq","name":"findElement","parameters":
{"using":"xpath","value":"//div[@id='fbLoginContainer']"}}
response: {"status":0,"value":{"ELEMENT":":wdc:1343173601466"}}
safari-extension://org.openqa.selenium-UASV6TAR75/f0a7decd/injected.js:
9283 [309.655s] [safaridriver.inject.Tab.TOP] [crkc5ck3dll2] Executing
{"id":"dpw4pi63q2o8","name":"executeScript","parameters":{"args":
[{"ELEMENT":":wdc:1343173601466"}],"script":"if(document.createEvent)
{var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}
safari-extension://org.openqa.selenium-UASV6TAR75/f0a7decd/injected.js:
9283 [309.656s] [safaridriver.inject.PageScript] Sending message:
{"origin":1,"type":"command","command":
{"id":"dpw4pi63q2o8","name":"executeScript","parameters":{"args":
[{"ENCODED_ELEMENT":"/HTML/BODY/DIV[5]/DIV/DIV/DIV[2]/DIV[2]/SPAN/
DIV"}],"script":"if(document.createEvent){var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}}
all.js:44Received message of type object from http://www.treat.com,
expected a string
page.js:6009 [158.782s] [safaridriver.inject.page] Sending
executeScript response: {"origin":
2,"type":"response","id":"dpw4pi63q2o8","response":{"status":
0,"value":null}}
all.js:44Received message of type object from http://www.treat.com,
expected a string
safari-extension://org.openqa.selenium-UASV6TAR75/f0a7decd/injected.js:
9283 [309.672s] [safaridriver.inject.Tab.TOP] [crkc5ck3dll2] Sending
response
command: {"id":"dpw4pi63q2o8","name":"executeScript","parameters":
{"args":[{"ENCODED_ELEMENT":"/HTML/BODY/DIV[5]/DIV/DIV/DIV[2]/DIV[2]/
SPAN/DIV"}],"script":"if(document.createEvent){var evObj =
document.createEvent('MouseEvents');evObj.initEvent('click', true,
false); arguments[0].dispatchEvent(evObj);} else
if(document.createEventObject)
{ arguments[0].fireEvent('onclick');}"}}
response: {"status":0,"value":null}

On Jul 24, 3:35 pm, Peter Gale <peterjeffreyg...@hotmail.co.uk> wrote:
> I can't see that WebDriver would prevent any javascript from working ... it just blindy passes the text you create to the browser for execution, even allowing invalid javascript or text which will cause the program to "hang" (perhaps waiting for a response) in my experience.
>
> Of course, the same javascript might potentially not work for all browsers, particularly if you accidentally have browser specific XPath, perhaps.
>
> It's a bit hard to tell, but I think your error message may refer to the WebDriver findElement command rather than the javascript call itself. I'd suggest doing your findElement calls on a line of their own and then passing a reference to the object returned so that i is clearer where the problem lies.
>
>
>
>
>
>
>
> > Date: Tue, 24 Jul 2012 15:27:09 -0700
> > Subject: [webdriver] What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> > From: manga...@gmail.com
> > To: webd...@googlegroups.com
>
> > Just wanted to check what types of javascript code won't work when
> > executed from SafariDriver with the js executor? Relative to other
> > browser drivers that is.
>
> > I've come across issues trying to click the login buttons of
> > integrated services like Facebook, Picasa, Flickr, etc., particularly
> > Facebook for the example on hand.
>
> > In Selenium RC, our workaround was to manually open the URLs to those
> > login pages (in a new window) to simulate clicking the login button
> > and then proceed from there. I would prefer not to have to deal with
> > URL alternatives in WebDriver.
>
> > Taking workaround example for mouseover issue
>
> >http://code.google.com/p/selenium/issues/detail?id=2067(comment #60),
> > all.js:44Received message of type object fromhttp://www.treat.com,
> > expected a string
> > page.js:6009 [ 61.531s] [safaridriver.inject.page] Sending
> > executeScript response: {"origin":
> > 2,"type":"response","id":"jqhymtzd3vg","response":{"status":
> > 0,"value":null}}
> > all.js:44Received message of type object fromhttp://www.treat.com,
> > expected a string
> > safari-extension://org.openqa.selenium-UASV6TAR75/646e2b5b/injected.js:
> > 9283 [146.088s] [safaridriver.inject.Tab.TOP] [ujzs3bkb1ljj] Sending
> > response
> > command:  {"id":"jqhymtzd3vg","name":"executeScript","parameters":
> > {"args":[{"ENCODED_ELEMENT":"/HTML/BODY/DIV[5]/DIV/DIV/DIV[2]/DIV[2]/
> > SPAN/DIV"}],"script":"if(document.createEvent){var evObj =
> > document.createEvent('MouseEvents');evObj.initEvent('click', true,
> > false); arguments[0].dispatchEvent(evObj);} else
> > if(document.createEventObject)
> > { arguments[0].fireEvent('onclick');}"}}
> > response: {"status":0,"value":null}
>
> > Easy to reproduce. Go towww.Treat.com, and attempt to click the

David

unread,
Jul 24, 2012, 8:02:52 PM7/24/12
to webdriver
Interestingly, I did another test using the javascript code to click
on a hyperlink element (anchor tag), and it worked. So for some reason
on Safari it won't work against custom buttons rendered from div
elements, but standard hyperlinks work.

driver.execute_script(clickScript,driver.find_element_by_link_text("Sign
In"))

Also, disregard my previous comment/question on xpecting string. I
forgot that the Safari console shows both normal web activity logs
along with SafariDriver activity, and that was non-SafariDriver stuff.
> all.js:44Received message of type object fromhttp://www.treat.com,
> expected a string
> page.js:6009 [158.782s] [safaridriver.inject.page] Sending
> executeScript response: {"origin":
> 2,"type":"response","id":"dpw4pi63q2o8","response":{"status":
> 0,"value":null}}
> all.js:44Received message of type object fromhttp://www.treat.com,
> expected a string

Peter Gale

unread,
Jul 25, 2012, 4:04:02 AM7/25/12
to webd...@googlegroups.com
What is the driver.execute_script method ... is that a custom extension you've written or is it part of the Safari driver?

I was expecting to see a simple javascript constructor somethign like this:

      JavascriptExecutor js = (JavascriptExecutor) driver;
      String strReturnValue = js.executeScript("myJavascript").toString();

I'm not sure what function the execute_script method does and what it adds to the process ... or possibly whether it is causing the problem.

It's curios that you pass it the name of a script and an element to work on, so there's obviously something else going on there that we might need to know about. Maybe that's the stage that is creating the failing javascript. Might be useful to see the actual javascript command that gets run from that method, if that's possible.

If possible, I'd ask you to try executing a script using the Javascript Exectutor approach, so we can see just what's in the script and nothing more.

And you can execute all the function in pure javascript as follows:

   javascript:document.getElementById('fbLoginContainer').click()

... so could you see if this works, too, using the simple javascript executor method?

If it fails, then you can also execute this script manually from the address bar within a (non-automated) browser session, as detailed here:

            http://mikeoff.blogspot.co.uk/2006/07/javascript-in-address-bar.html

... so you could then see if that code is rejected by the browser, in which case we'd know whether it is a driver issue of not.

If it does fail in the browser, I suspect that rendering div tags as buttons is possibly a breach of html standards (it certainly doesn't sound good practice) as div's are sussposed just to be organisational containers, I think, and maybe Safari abides by the standards in this respect.

> Date: Tue, 24 Jul 2012 17:02:52 -0700
> Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> From: mang...@gmail.com
> To: webd...@googlegroups.com

David

unread,
Jul 25, 2012, 1:32:43 PM7/25/12
to webdriver
Thanks, I'll give your suggestions for standalone js outside of
WebDriver a try.

FYI, the code I posted is using Python bindings to WebDriver. It's
unfortunate that Java is the default language of choice when
discussing issues.

Python's equivant to JavascriptExecutor is much simpler, simply
execute_script method within the driver class. No need to do the
casting from separate class. And I'm basically using the 2nd method
signature for executeScript(), which is it takes a string of
javascript, plus object(s) as argument. So clickScript is simply a
string containing the javascript to invoke, and the second argument I
pass is the WebElement, which is then referenced within the
clickScript (as argument[0]).

Unless there's a diff between bindings, the Python code should work
the same as what you suggest in Java. Reason I used Python is it was
easier to do exploratory automation development.

On Jul 25, 1:04 am, Peter Gale <peterjeffreyg...@hotmail.co.uk> wrote:
> What is the driver.execute_script method ... is that a custom extension you've written or is it part of the Safari driver?
>
> I was expecting to see a simple javascript constructor somethign like this:
>
>       JavascriptExecutor js = (JavascriptExecutor) driver;
>       String strReturnValue = js.executeScript("myJavascript").toString();
>
> I'm not sure what function the execute_script method does and what it adds to the process ... or possibly whether it is causing the problem.
>
> It's curios that you pass it the name of a script and an element to work on, so there's obviously something else going on there that we might need to know about. Maybe that's the stage that is creating the failing javascript. Might be useful to see the actual javascript command that gets run from that method, if that's possible.
>
> If possible, I'd ask you to try executing a script using the Javascript Exectutor approach, so we can see just what's in the script and nothing more.
>
> And you can execute all the function in pure javascript as follows:
>
>    javascript:document.getElementById('fbLoginContainer').click()
>
> ... so could you see if this works, too, using the simple javascript executor method?
>
> If it fails, then you can also execute this script manually from the address bar within a (non-automated) browser session, as detailed here:
>
>            http://mikeoff.blogspot.co.uk/2006/07/javascript-in-address-bar.html
>
> ... so you could then see if that code is rejected by the browser, in which case we'd know whether it is a driver issue of not.
>
> If it does fail in the browser, I suspect that rendering div tags as buttons is possibly a breach of html standards (it certainly doesn't sound good practice) as div's are sussposed just to be organisational containers, I think, and maybe Safari abides by the standards in this respect.
>
>
>
>
>
>
>
> > Date: Tue, 24 Jul 2012 17:02:52 -0700
> > Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> > From: manga...@gmail.com
> ...
>
> read more »

David

unread,
Jul 25, 2012, 2:17:03 PM7/25/12
to webdriver
The address bar method didn't seem to work for me, even in Firebug.
Tested out using (javascript) console in the browsers w/o using
WebDriver. Worked in all browsers except Safari.

Perhaps your assumption about Safari adhering to standards is correct
or there's some other issues with Safari.

I ran the following code snippet in console
"document.getElementById('fbLoginContainer').click();"

For IE ran with Firebug Lite console, for Safari, ran with same plus
Safari's Web Inspector console. Safari returns this error in the
console:

TypeError: 'undefined' is not a function (evaluating
'document.getElementById('fbLoginContainer').click()')

Error
line: 2
message: "'undefined' is not a function (evaluating
'document.getElementById('fbLoginContainer').click()')"
sourceId: 2078392448
__proto__: Error

But what is interesting if the issue is about standards is that in
Safari, the divs are rendered fine like buttons and can be clicked on
manually and they work. Just can't be clicked on via javascript nor
automated tools like Selenium. In this case, only true workaround is
something like Sikuli or AutoIt to do the clicking.

On Jul 25, 1:04 am, Peter Gale <peterjeffreyg...@hotmail.co.uk> wrote:
> What is the driver.execute_script method ... is that a custom extension you've written or is it part of the Safari driver?
>
> I was expecting to see a simple javascript constructor somethign like this:
>
>       JavascriptExecutor js = (JavascriptExecutor) driver;
>       String strReturnValue = js.executeScript("myJavascript").toString();
>
> I'm not sure what function the execute_script method does and what it adds to the process ... or possibly whether it is causing the problem.
>
> It's curios that you pass it the name of a script and an element to work on, so there's obviously something else going on there that we might need to know about. Maybe that's the stage that is creating the failing javascript. Might be useful to see the actual javascript command that gets run from that method, if that's possible.
>
> If possible, I'd ask you to try executing a script using the Javascript Exectutor approach, so we can see just what's in the script and nothing more.
>
> And you can execute all the function in pure javascript as follows:
>
>    javascript:document.getElementById('fbLoginContainer').click()
>
> ... so could you see if this works, too, using the simple javascript executor method?
>
> If it fails, then you can also execute this script manually from the address bar within a (non-automated) browser session, as detailed here:
>
>            http://mikeoff.blogspot.co.uk/2006/07/javascript-in-address-bar.html
>
> ... so you could then see if that code is rejected by the browser, in which case we'd know whether it is a driver issue of not.
>
> If it does fail in the browser, I suspect that rendering div tags as buttons is possibly a breach of html standards (it certainly doesn't sound good practice) as div's are sussposed just to be organisational containers, I think, and maybe Safari abides by the standards in this respect.
>
>
>
>
>
>
>
> > Date: Tue, 24 Jul 2012 17:02:52 -0700
> > Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> > From: manga...@gmail.com
> ...
>
> read more »

Peter Gale

unread,
Jul 25, 2012, 3:05:36 PM7/25/12
to webd...@googlegroups.com
Sorry ... missed the reference to Python!

I can't see a reference to fbLoginContainer on my Facebook login page ... if you can post a snippet of the html around this element as you see it, we might be able to suggest working XPath alternatives that will work directly from Selenium ... I can't believe there won't be at least one option that we can't get working.

> Date: Wed, 25 Jul 2012 11:17:03 -0700

> Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?

David

unread,
Jul 26, 2012, 2:09:35 AM7/26/12
to webdriver
No worries, understandable to mistake code when I didn't state it was
Python and one hasn't worked in that language binding much.

The element is not on Facebook login page. This is one of those
Facebook Connect/login integration with 3rd party site things, that
are harder to test than Facebook's site itself. Clicking it launches
popup to Facebook login page that on login auto closes popup and main
window refreshes w/ logged in status of FB account.

The site in question is www.treat.com. You'll see it on the home page.

I never got it to work for IE and Safari under Selenium RC. But with
WebDriver thanks to true javascript execution support, got IE to work,
but not Safari still.

On Jul 25, 12:05 pm, Peter Gale <peterjeffreyg...@hotmail.co.uk>
wrote:
> Sorry ... missed the reference to Python!
>
> I can't see a reference to fbLoginContainer on my Facebook login page ... if you can post a snippet of the html around this element as you see it, we might be able to suggest working XPath alternatives that will work directly from Selenium ... I can't believe there won't be at least one option that we can't get working.
>
>
>
>
>
>
>
> > Date: Wed, 25 Jul 2012 11:17:03 -0700
> > Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> > From: manga...@gmail.com
> ...
>
> read more »

Peter Gale

unread,
Jul 26, 2012, 3:57:34 AM7/26/12
to webd...@googlegroups.com
OK ... I see that the "fbLoginContainer" div element is completely empty and its appearance is completely controlled by CSS. This may be what confused the clicking action in Selenium.

Firstly could you try these two methods to see if clicking via the parent element, or just clicking the parent element itself, works:

    driver.findElement(ByXpath,"//span/[@id='headerFBsignin']/div").click

    driver.findElement(ByXpath,"//span/[@id='headerFBsignin']").click


Secondly, I understand that Selenium simply clicks on the screen at the centre of the element's screen area, so it could be useful to know where exactly Selenium thiinks this element is on the screen and what area it takes up. So it would be helpful if you could get these values from the "fbLoginContainer" element:

    driver.findElement(By.xpath(strXPath)).getLocation()
    driver.findElement(By.xpath(strXPath)).getSize().height()
    driver.findElement(By.xpath(strXPath)).getSize().width()

Firebug seems to tell me that the element is 22x74 pixels.

Another option, then, would be to force the click to occur somewhere offset from the centre of the element, which I think you can do with the Action class as follows:

   int xOffset = 100;
   Actions builder = new Actions(webDriver);
   builder.MoveToElement(element, xOffset, 0);
   builder.Click();


Not sure what offset to suggest until we know what height and width WebDriver returns.



> Date: Wed, 25 Jul 2012 23:09:35 -0700

> Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?

David

unread,
Jul 26, 2012, 5:00:25 PM7/26/12
to webdriver
I used Python, easier for me to try things out with, and SafariDriver
returned the same size as you mention 74 width by 22 height.

As for location, it returned x 479, y 41, hCode of 1004535808.

What offset do you propose based on this info?

On Jul 26, 12:57 am, Peter Gale <peterjeffreyg...@hotmail.co.uk>
wrote:
> OK ... I see that the "fbLoginContainer" div element is completely empty and its appearance is completely controlled by CSS. This may be what confused the clicking action in Selenium.
>
> Firstly could you try these two methods to see if clicking via the parent element, or just clicking the parent element itself, works:
>
>     driver.findElement(ByXpath,"//span/[@id='headerFBsignin']/div").click
>
>     driver.findElement(ByXpath,"//span/[@id='headerFBsignin']").click
>
> Secondly, I understand that Selenium simply clicks on the screen at the centre of the element's screen area, so it could be useful to know where exactly Selenium thiinks this element is on the screen and what area it takes up. So it would be helpful if you could get these values from the "fbLoginContainer" element:
>
>     driver.findElement(By.xpath(strXPath)).getLocation()
>
>     driver.findElement(By.xpath(strXPath)).getSize().height()
>     driver.findElement(By.xpath(strXPath)).getSize().width()
>
> Firebug seems to tell me that the element is 22x74 pixels.
>
> Another option, then, would be to force the click to occur somewhere offset from the centre of the element, which I think you can do with the Action class as follows:
>
>    int xOffset = 100;
>
>    Actions builder = new Actions(webDriver);
>
>    builder.MoveToElement(element, xOffset, 0);
>
>    builder.Click();
>
> Not sure what offset to suggest until we know what height and width WebDriver returns.
>
>
>
>
>
>
>
> > Date: Wed, 25 Jul 2012 23:09:35 -0700
> > Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
> > From: manga...@gmail.com
> > To: webd...@googlegroups.com
>
> > No worries, understandable to mistake code when I didn't state it was
> > Python and one hasn't worked in that language binding much.
>
> > The element is not on Facebook login page. This is one of those
> > Facebook Connect/login integration with 3rd party site things, that
> > are harder to test than Facebook's site itself. Clicking it launches
> > popup to Facebook login page that on login auto closes popup and main
> > window refreshes w/ logged in status of FB account.
>
> > The site in question iswww.treat.com. You'll see it on the home page.
> ...
>
> read more »

David

unread,
Jul 26, 2012, 5:03:02 PM7/26/12
to webdriver
By the way, I also tried the alternate locators you mention, and it
hung the driver, my Python session just hung, and the SafariDriver
console showed this:

[ 99.064s] [safaridriver.inject.Tab.TOP] [10tj4h3nimby] Executing
{"id":"opgx9h6j16m0","name":"findElement","parameters":
{"using":"xpath","value":"//span/[@id='headerFBsignin']"}}
safari-extension://org.openqa.selenium-UASV6TAR75/779d552e/injected.js:
9283 [ 99.068s] [safaridriver.inject.Tab.TOP] [10tj4h3nimby] Sending
response
command: {"id":"opgx9h6j16m0","name":"findElement","parameters":
{"using":"xpath","value":"//span/[@id='headerFBsignin']"}}
response: {"status":32,"value":{"message":"Unable to locate an element
with the xpath expression //span/[@id='headerFBsignin'] because of the
following error:\nError: INVALID_EXPRESSION_ERR: DOM XPath Exception
51"}}

both XPath locators you suggested resulted in this type of exception
in the driver. Just locating by ID 'headerFBsignin' didn't cause this
type of issue, but the click didn't do anything either.
> ...
>
> read more »

David

unread,
Jul 26, 2012, 5:27:08 PM7/26/12
to webdriver
Strange, now it works today in Safari, just clicking on it with the
original element with Python and Java bindings. For some weird reason
it didn't work when I tried it out yesterday. Perhaps Safari is less
stable than the other browsers...I'll monitor its success rate over
time.

But still interested in what you would suggest regarding the actions
class. Thanks for the help.
> ...
>
> read more »

Peter Gale

unread,
Jul 26, 2012, 6:01:26 PM7/26/12
to webd...@googlegroups.com
The error messge: "INVALID_EXPRESSION_ERR: DOM XPath Exception 51" seems to originate form this w3.org specification: http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#Interfaces

I don't understand the meaning or significance of that but it seems to indicate that there is a relevant standard in play and that it might well be being breached somehow.

I'm not sure what offset to try, you could try anything from minus half the width to + half the width and see if it works or is more consistent.

I see that the "Sign-in" link to the right of the facebook icon is more of a traditional anchor style link. So it might be worth trying to link as an offset from this as a base element in the action class element to try to bypass any issues with the definition of the div element, if you see what I mean. You'd need to use a minus offset of half the width of the sigin-in icon, plus half the with of the facbook icon, plus the gap between (determined from the difference between the horizontal locations of the two elements less the width of the facebook icon). Sounds convoluted but may just work!?

However, if clicking on the div element by the regular id now works, and it stays working, it might just have been a temporary glitch ... hopefully!

> Date: Thu, 26 Jul 2012 14:27:08 -0700

> Subject: [webdriver] Re: What types of javascript won't work under SafariDriver? Javascript mouse click not supported by SafariDriver?
Reply all
Reply to author
Forward
0 new messages