Safari Driver throws org.openqa.selenium.WebDriverException: Cannot set the selection end

1,410 views
Skip to first unread message

Pavithra

unread,
Aug 13, 2012, 3:25:17 AM8/13/12
to webd...@googlegroups.com
Just started using Safari Driver as per http://code.google.com/p/selenium/wiki/SafariDriver
Launched Safari using below code:
capability = DesiredCapabilities.safari();
driver = new RemoteWebDriver(new URL("http://" + serverIp + ":" + serverPort + "/wd/hub"), capability);
return driver;

org.openqa.selenium.WebDriverException: Cannot set the selection end error is thrown when I am trying to type on the element inside iframe.
I switched to iframe using switchto frame (based on frame name).

Below is the element xpath inside iframe (from safari browser):
<html>
 <head>
   <style></style>
   <body style="padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; font-size: 13px; font-family: Arial, Helvetica, sans-serif; color: black; " contenteditable="true" unselectable="off"></body>
</html>

element is identified as xpath,/html/body

While trying to type on the above element it throws the error: org.openqa.selenium.WebDriverException: Cannot set the selection end

Note: Only in Safari browser, while inspecting I could see
contenteditable="true" unselectable="off" and not in other browsers. What does this mean?
How to resolve the above error?
Kindly help!!

Note: Same sendKeys works fine with other browsers: IE, FF, Chrome.

--Pavithra

Pavithra

unread,
Aug 13, 2012, 3:27:22 AM8/13/12
to webd...@googlegroups.com
Sorry missed to close the head tag before body tag.
Dom Structure is like this:
<html>
<head></head>
<body></body>
</html>

Jason Leyba

unread,
Aug 13, 2012, 1:43:48 PM8/13/12
to webd...@googlegroups.com
The SafariDriver does not support typing in contentEditable fields.

-- Jason

Pavithra Navaneeth

unread,
Aug 13, 2012, 1:47:30 PM8/13/12
to webd...@googlegroups.com
Jason,
Thanks for the info!!
Is there any alternative to type in such fields?

Note: In other browsers, I am not seeing this attributes: contenteditable="true" unselectable="off"
It appears only in safari browser while inspecting. Any reason?

--Pavithra

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/bwmENbQeKdMJ.

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.



--
Thanks & Regards,
Pavithra Navaneeth

David

unread,
Aug 13, 2012, 6:48:41 PM8/13/12
to webdriver
some thoughts...

modify the DOM via javascript to remove those attributes or change the
value of those attributes. then continue with typing into the field
not sure if that's possible though.

fake user agent of browser, unfortunately, I believe you can't do that
with SafariDriver so that won't help. But for fun/testing, you could
try faking user agent of Firefox to pretend to be Safari (I think that
was editing profile settings, etc. for user agent parameter), and see
if the attributes show up. I'm guessing the site you are testing,
checks against Safari and renders differently or such.

On Aug 13, 10:47 am, Pavithra Navaneeth <pavi...@gmail.com> wrote:
> Jason,
> Thanks for the info!!
> Is there any alternative to type in such fields?
>
> Note: In other browsers, I am not seeing this attributes:
> contenteditable="true"
> unselectable="off"
> It appears only in safari browser while inspecting. Any reason?
>
> --Pavithra
>
>
>
>
>
>
>
>
>
> On Mon, Aug 13, 2012 at 11:13 PM, Jason Leyba <jmle...@gmail.com> wrote:
> > The SafariDriver does not support typing in contentEditable fields.
>
> > -- Jason
>
> > On Monday, August 13, 2012 12:27:22 AM UTC-7, Pavithra wrote:
>
> >> Sorry missed to close the head tag before body tag.
> >> Dom Structure is like this:
> >> <html>
> >> <head></head>
> >> <body></body>
> >> </html>
>
> >> On Monday, August 13, 2012 12:55:17 PM UTC+5:30, Pavithra wrote:
>
> >>> Just started using Safari Driver as perhttp://code.google.com/p/**
> >>> selenium/wiki/SafariDriver<http://code.google.com/p/selenium/wiki/SafariDriver>
> >>> Launched Safari using below code:
> >>> capability = DesiredCapabilities.safari();
> >>> driver = new RemoteWebDriver(new URL("http://" + serverIp + ":" +
> >>> serverPort + "/wd/hub"), capability);
> >>> return driver;
>
> >>> org.openqa.selenium.**WebDriverException: Cannot set the selection end
> >>> error is thrown when I am trying to type on the element inside iframe.
> >>> I switched to iframe using switchto frame (based on frame name).
>
> >>> Below is the element xpath inside iframe (from safari browser):
> >>> <html>
> >>>  <head>
> >>>    <style></style>
> >>>    <body style="padding-top: 15px; padding-right: 15px; padding-bottom:
> >>> 15px; padding-left: 15px; font-size: 13px; font-family: Arial, Helvetica,
> >>> sans-serif; color: black; " contenteditable="true"
> >>> unselectable="off"></body>
> >>> </html>
>
> >>> element is identified as xpath,/html/body
>
> >>> While trying to type on the above element it throws the error:
> >>> org.openqa.selenium.**WebDriverException: Cannot set the selection end

Pavithra

unread,
Feb 4, 2013, 5:15:23 AM2/4/13
to webd...@googlegroups.com
Deepankur,
Not yet. I am also checking :-(
But I could see java script executor can be used with document.evaluate syntax to type in it. But I am not sure about the exact syntax ...

On Wednesday, 16 January 2013 18:01:30 UTC+5:30, Deepankur Tyagi wrote:
Hi Pavithra,
Have you found answer of this problem. I am struggling with it too?
Thanks
Deepankur

Jason Leyba

unread,
Apr 3, 2013, 4:10:41 PM4/3/13
to webd...@googlegroups.com
It's a limitation of the SafariDriver and not likely to be fixed.

https://code.google.com/p/selenium/issues/detail?id=4467

On Friday, March 29, 2013 2:50:10 AM UTC-7, Moldovan Ionut Emilian wrote:
I also have this problem , when sendkeys to xptah :  /html/body  ->  on Safari , for  IE ,FF , GC works just fine .   
Does anyone know if this is a Safari Driver Bug , should we Log a Bug somewhere and maybe it will get solve ?

Pavithra

unread,
May 14, 2013, 1:53:55 AM5/14/13
to webd...@googlegroups.com
After switching to iframe: driver.switchTo().frame("frame_name")

Here is the solution we have to type inside iframe in safari:

if (browser_name.equalsIgnoreCase("safari") && (typeInsideFrame.equalsIgnoreCase("true")))       

 {

            ((JavascriptExecutor) driver) .executeScript( "var div = document.getElementsByTagName (\"body\")[0];if (div.contentEditable == \"true\") {div.contentEditable = \"false\";var text=div.innerHTML;div.innerHTML = text+arguments[0];}",value);

        } 

It directly inserts the value to be typed inside the html dom.

Hope it helps!!

Thanks
Pavithra

Iuliana Pavaloaie

unread,
Feb 4, 2015, 11:50:56 AM2/4/15
to webd...@googlegroups.com
You can always use Java Robot class instead. You only need to click in the text area first.
After:

    Robot robot = new Robot();
    robot.setAutoDelay(40);
    robot.setAutoWaitForIdle(true);

    Thread.sleep(2500);

    //type is defined elsewhere - not illustrating for this example 
    Keyboard keyboard = new Keyboard();
    Thread.sleep(500);
    
    keyboard.type(headlineText);
    Thread.sleep(500);


    Thread.sleep(3500);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
Reply all
Reply to author
Forward
0 new messages