WebDriverException when I use a proxy with ChromeDriver - selenium-webdriver

When I use a proxy with ChromeDriver I have Class Cast Exception.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
if (!Context.getProxy().isEmpty()) {
Proxy proxy = new Proxy();
proxy.setHttpProxy(Context.getProxy());
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);
return new ChromeDriver(capabilities);
if Context.getProxy().isEmpty() = true, I Web driver is ok, but if I Set a proxy I have this error:
org.openqa.selenium.WebDriverException: Unable to convert: Capabilities [{ensureCleanSession=true, proxy=Proxy(manual, http=renn.proxy.corp.xxxx:8080), loggingPrefs=org.openqa.selenium.logging.LoggingPreferences#5df041, browserName=chrome, version=, platform=ANY, unexpectedAlertBehaviour=accept}]
at org.openqa.selenium.remote.BeanToJsonConverter.convert(BeanToJsonConverter.java:69)
...
...
Caused by: org.openqa.selenium.WebDriverException: Unable to convert: Capabilities [{ensureCleanSession=true, proxy=Proxy(manual, http=renn.proxy.corp.xxxx:8080), loggingPrefs=org.openqa.selenium.logging.LoggingPreferences#5df041, browserName=chrome, version=, platform=ANY, unexpectedAlertBehaviour=accept}]
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'ITEM-72885', ip: '192.168.84.9', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:88)
at org.openqa.selenium.remote.BeanToJsonConverter.convert(BeanToJsonConverter.java:66)
... 84 more
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:223)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:143)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:189)
at org.openqa.selenium.remote.BeanToJsonConverter.convertObject(BeanToJsonConverter.java:86)
... 85 more

Problem resolved when I upgraded the driver version.

Related

How to open a tab in safari using Selenium in Java

I've been trying to open tabs in browsers via Selenium and seems to work on all except Safari.
I'm trying the following:
public void openNewTab(String url) {
((JavascriptExecutor) getWebDriver()).executeScript("window.open('" + url + "','_blank');");
}
I've seen some answers in other languages to pass the --legacy argument but not an equivalent for Java.
Any hints?
Update
Some related answers include:
Request body does not contain required parameter 'handle'
Here's the error I'm getting when trying the code on the following OS via SauceLabs:
Mac 10.13
Mac 10.14
iPad Pro (12.9 inch) Simulator
org.openqa.selenium.InvalidArgumentException: Request body does not contain required parameter 'handle'.
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'itako4501.prod.miso', ip: 'fe80:0:0:0:ca0:e26a:55bf:fecd%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '9.0.4'
Driver info: driver.version: unknown
Command duration or timeout: 0 milliseconds
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:903)
Caused by: org.openqa.selenium.InvalidArgumentException: Request body does not contain required parameter 'handle'.
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'itako4501.prod.miso', ip: 'fe80:0:0:0:ca0:e26a:55bf:fecd%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '9.0.4'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'x-r', ip: 'fe80:0:0:0:4ac:2f6c:527b:c271%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '11.0.3'
Driver info: driver.version: unknown
This will open a new tab. tried on MacOs Mojave safari Version 12.1.2 (14607.3.9)
driver.get("http://google.com");
((JavascriptExecutor) driver).executeScript("window.open('http://cnn.com','_blank');");

org.openqa.selenium.WebDriverException method is not implemented

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "9c37fa48");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "8");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.xxx.yyy");
capabilities.setCapability("appActivity", "com.xxx.yyy.MainActivity");
capabilities.setCapability("appWaitActivity", "com.xxx.yyy.MainActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
What i see is the code tries to access the app.. After that i get the below exception.
Mar 05, 2019 3:37:23 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Mar 05, 2019 3:37:34 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '405' -> incorrect JSON status mapping for 'unknown error' (500 expected)
FAILED: setUp
org.openqa.selenium.WebDriverException: Method is not implemented
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'M710S-MDT06', ip: '192.168.7.148', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {appActivity: com.wizlearn.tmlearn.MainAc..., appPackage: com.wizlearn.tmlearn, appWaitActivity: com.wizlearn.tmlearn.MainAc..., databaseEnabled: false, desired: {appActivity: com.wizlearn.tmlearn.MainAc..., appPackage: com.wizlearn.tmlearn, appWaitActivity: com.wizlearn.tmlearn.MainAc..., deviceName: 9c37fa48, platformName: android, platformVersion: 8}, deviceManufacturer: samsung, deviceModel: SM-T825Y, deviceName: 9c37fa48, deviceScreenSize: 1536x2048, deviceUDID: 9c37fa48, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: LINUX, platformVersion: 8.0.0, takesScree`enter code here`nshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 8a08634e-3e25-4f30-a114-8b315070fc57
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Appium desktop version: 1.11.0
java version "1.8.0_201"
Selenium 3.141.59
Earlier I used Selenium remote web driver for windows 8.1
For Widnows 10, changed to Anroid Driver .
WebDriver driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Now it works!!

I am getting error while maximazing the chrome window

I am facing the problem while executing the code to maximize the window.
Below is the error message:
unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.03 seconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'SDN-117', ip: '172.10.189.52', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_73'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users\TANUJA~1\AppData\Local\Temp\scoped_dir9140_12941}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 12757c3f618b72bfaffb8713a175d458
Kindly help me to sort out the problem.
Here is the Answer to your Question:
To maximize Google Chrome browser window it is recommended to use ChromeOptions class instead of driver.manage().window().maximize();. Here is the sample code for your reference:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
Let me know if this Answers your Question.

I am getting 80% time error on running protractor scripts on IE 11

My protractor scripts are highly stable on chrome browser but the same scripts throws below mentioned for 20% of the test cases.
Failed: JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 100 milliseconds
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'LAPTOP-RNQ2JQBE', ip: '192.168.89.115', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=true, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:41897/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: f32d0eb8-65d9-4161-9535-da5cde8b9a6c
Failed: Error while waiting for Protractor to sync with the page:
"Unable to get property '$$testability' of undefined or null
reference"

Firefox not getting launched from Ant and TestNg combination

I am using Selenium 2.53.0 and Firefox version is 46.0.1.
Please find the code below which i am running from Ant :
#Test
public void Browser() {
// Luanching Firefox browser
FirefoxDriver driver=new FirefoxDriver();
driver.get("http://flipkart.com");
driver.quit();
}
Note:
If I run the code from eclipse working as expected without any issues. But if I run the same code from Ant using Build.xml, I am getting below error:
**org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within45000 ms**
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: firefox
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:46) at org.openqa.selenium.firefox.FirefoxDriver.connectTo(FirefoxDriver.java:139)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:129)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:109)
at test.NewTest.Browser(NewTest.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.Met
Please suggest a solution how to resolve above mentioned issue ?

Resources