Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafariDriver: assumes that all returned JavaScript objects with nodeType: 1 are HTMLElement nodes #2583

Closed
mfulton26 opened this issue Aug 8, 2016 · 2 comments

Comments

@mfulton26
Copy link

Meta -

OS: Mac OS X
OS Version: 10.11
Selenium Version: 2.53.1
Browser: Safari
Browser Version: 9.0

Expected Behavior -

Objects returned from JavascriptExecutor.executeScript(String) may contain properties named "nodeType" with value 1 and not be HTMLElement nodes.

Actual Behavior -

Attempting to get any object via JavascriptExecutor.executeScript(String) which has a property named "nodeType" and a value of 1 causes a WebDriverException with message, "undefined is not an object (evaluating 'c.tagName.toLowerCase')".

Steps to reproduce -

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;

public class SafariAssumedElementDemo {
    public static void main(String... args) throws MalformedURLException {
        String username = System.getenv("SAUCE_USERNAME");
        String accessKey = System.getenv("SAUCE_ACCESS_KEY");
        String host = "ondemand.saucelabs.com:80";
        URL remoteAddress = new URL(String.format("http://%s:%s@%s/wd/hub", username, accessKey,
                host));
        DesiredCapabilities desiredCapabilities = DesiredCapabilities.safari();
        desiredCapabilities.setPlatform(Platform.EL_CAPITAN);
        desiredCapabilities.setVersion("latest");
        WebDriver webDriver = new RemoteWebDriver(remoteAddress, desiredCapabilities);
        try {
            JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webDriver;
            javascriptExecutor.executeScript("return { nodeType: 1 }");
        } finally {
            webDriver.quit();
        }
    }
}

Example Output -

Exception in thread "main" org.openqa.selenium.WebDriverException: undefined is not an object (evaluating 'c.tagName.toLowerCase') (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14 milliseconds
Build info: version: '2.48.0', revision: 'b7b081a', time: '2015-10-07 15:48:56'
System info: host: 'itako47035.prod.miso', ip: '172.20.47.35', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=9.0, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}]
Session ID: null
Command duration or timeout: 321 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'NTISP138', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{webdriver.remote.sessionid=18708d5480904f159be40770f90149f3, takesScreenshot=true, browserName=safari, javascriptEnabled=true, hasMetadata=true, version=9.0, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}]
Session ID: 18708d5480904f159be40770f90149f3
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:577)
    at SafariAssumedElementDemo.main(SafariAssumedElementDemo.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.openqa.selenium.WebDriverException: undefined is not an object (evaluating 'c.tagName.toLowerCase') (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14 milliseconds
Build info: version: '2.48.0', revision: 'b7b081a', time: '2015-10-07 15:48:56'
System info: host: 'itako47035.prod.miso', ip: '172.20.47.35', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=9.0, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}]
Session ID: null
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'NTISP138', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: EventFiringWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:556)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:102)
    at com.sun.proxy.$Proxy1.executeScript(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.executeScript(EventFiringWebDriver.java:216)
    at org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteScript.java:56)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
@mfulton26 mfulton26 changed the title SafariDriver: assumes that all returned JavaScript objects with nodeType: 1 are a HTMLElement nodes SafariDriver: assumes that all returned JavaScript objects with nodeType: 1 are HTMLElement nodes Aug 8, 2016
@jleyba jleyba added the D-safari label Aug 8, 2016
@jleyba
Copy link
Contributor

jleyba commented Aug 8, 2016

Yes, element detection is not very smart. Here's the relevant code:

https://github.com/SeleniumHQ/selenium/blob/safari/javascript/safari-driver/inject/encoder.js#L150

@lukeis
Copy link
Member

lukeis commented Sep 23, 2016

With the release of Safari 10, Apple now offers official support WebDriver. Because of this, the Selenium project no supports the legacy implementation from 2.x.

Users are advised to switch to Apple's driver and file bugs at
https://bugreport.apple.com/

We are no longer tracking issues for Selenium's SafariDriver and thus closing this issue.

@lukeis lukeis closed this as completed Sep 23, 2016
@lock lock bot locked and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants