error "network connection must be enabled" while setting networkConnection with ChromeDriver - selenium

I'm running a JUnit test of my Wicket project with the help of selenium and chrome driver.
Our website supports HTML5 offline mode using manifest and all, which we also want to test.
We use ChromeDriver like:
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("binary", binarylocation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
capabilities.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
driver = new ChromeDriver(capabilities);
But unfourtnetly, there is an error when trying this in the middle of my test:
((NetworkConnection) chromeDriver).setNetworkConnection(ConnectionType.NONE);
The error is:
org.openqa.selenium.WebDriverException: unknown error: network connection must be enabled
(Session info: chrome=57.0.2987.98)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'xxx', ip: 'xx.xx.xx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\xxx\AppData\Local\Temp\scoped_dir164_11339}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=57.0.2987.98, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: c344d7f922bc0973d46959e17103672c
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)
at org.openqa.selenium.remote.mobile.RemoteNetworkConnection.setNetworkConnection(RemoteNetworkConnection.java:46)
at org.openqa.selenium.chrome.ChromeDriver.setNetworkConnection(ChromeDriver.java:230)
Regarding this: https://bugs.chromium.org/p/chromedriver/issues/detail?id=984 this feature should be possible, but somehow it's not?
Could someone give me a hint?

This seems to be intended for mobile emulation. I tested this and was able to reproduce your error, and then fix it by enabling mobile emulation, i.e.:
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Laptop with touch");
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);
chromeOptions.put("binary", binarylocation);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
capabilities.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
driver = new ChromeDriver(capabilities);
I thought you might just need to set the network type to airplane mode, not none, but that didn't work (without also enabling mobile emulation).

Related

session null does not exist (WARNING: The server did not provide any stacktrace information

I am actually new to selenium, I have automated the website successfully using Firefox driver but when I tried the same code in IE am getting the subjected error in the driver.get(URL) line I used two different type simple code to open the browser and navigate to google which is not working.
please help me resolve this issue with IEDriver.
code 1:
System.setProperty("webdriver.ie.driver", "D:\\otherdata\\Selenium\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver();
driver.get("www.google.com");
code 2:
DesiredCapabilities IEcaps = DesiredCapabilities.internetExplorer();
IEcaps .setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
File SrcFile= new File("D:\\other data\\Selenium\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", SrcFile.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver(IEcaps );
driver.get("www.google.com");
ERROR:
Started InternetExplorerDriver server (32-bit)
3.5.1.0
Listening on port 5424
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: session null does not exist (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:32:46'
System info: host: 'MGK-PC', ip: '192.168.1.108', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{capabilities={acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:5424/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=true}, browserName=internet explorer, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, platformName=windows, setWindowRect=true}, sessionId=668e028c-b9e5-4ddc-8d0a-f2d61ac62bde, platform=ANY}]
Session ID: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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.get(RemoteWebDriver.java:316)
at New.IE_Test.main(IE_Test.java:27)

Not able to check 2nd checkbox. Getting org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (106, 655)

I am getting WebDriverException while trying to select the 2nd checkbox in the list. I am able to select the 1st check box but on the 2nd time my code throwing exception. Please find the method that i am using and exception message below.
Note: Any suggestion will be helpful for me.
URL: https://www.snapdeal.com/products/computers-external-hard-drives?sort=plrty&q=Capacity_s%3A1%20TB%7C
public void capacitySelection(String capacity){
WebDriverWait wd = new WebDriverWait(driver, 180);
List<WebElement> cList = wd.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[#data-name='Capacity_s']/div")));
int i=1;
for(WebElement we:cList){
WebElement select= wd.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#data-name='Capacity_s']/div["+ i++ +"]/label")));
if(select.getText().contains(capacity)){
select.click();
break;
}
}
}
Exception Message:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (106, 655). Other element would receive the click: <label for="Capacity_s-3TB">...</label>
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.2.9200 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Bishnu', ip: '192.168.0.107', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Bishnu\AppData\Local\Temp\scoped_dir11044_5076}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=54.0.2840.99, platform=WIN8, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 505ec9fb429bc6b9806edb52d75856f0
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at in.prolearn.pages.HomePage.SecondCapacitySelection(HomePage.java:59)
at in.prolearn.testcases.VerifySnapDealSelection.main(VerifySnapDealSelection.java:22)
Thanks.
Can you use JavaScript instead
WebElement product = new WebDriverWait(aDriverInstance, 5L).
until(ExpectedConditions.visibilityOfElementLocatedBy(By.id("anID")));
JavascriptExecutor jsExec = (JavascriptExecutor) aDriverInstance;
jsExec.executeScript("arguments[0].scrollIntoView()", product);
Actions actions = new Actions(driver);
actions.moveToElement(select).click().perform();
Try to click the element with Actions class. This will help you.
Use .isSelected() method before performing click on that element.

Why I am not able to handle the password field using selenium web driver in new gmail login page?

I am new to selenium web driver, I am writing script to login in to the gmail below is the test script that I created.
public class gmailEmail {
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByName("signIn").click();
driver.findElementById("Passwd").sendKeys("XXXX");
//driver.findElementByXPath("//*[#id='Passwd']").sendKeys("XXXXX");
driver.findElementByXPath("//*[#id='signIn']").click();
}
When I run this the error is triggering at "driver.findElementById("Passwd")" following error message is displaying
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"Passwd"}
(Session info: chrome=49.0.2623.112)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 40 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'Rameshs-MacBook-Pro.local', ip: '192.168.0.105', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/vx/07vnt7mn2jx4fpm983_tq6gm0000gn/T/.org.chromium.Chromium.S1jNgs}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.112, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: f5790b0589eb054c4e11283c80b82f0e
*** Element info: {Using=id, value=Passwd}
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.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
at MobilousLogin.gmailEmail.login(gmailEmail.java:15)
at MobilousLogin.Registration.main(Registration.java:10)
If I debug by inserting a breakpoint at "driver.findElementById("Passwd")" then the whole script is working fine.
Can some one please help me out in understanding what I am doing wrong here?
The error says it isn't able to identify the element that means by the time selenium has executed the command to enter password, the element wasn't loaded or not visible in the UI.
You may want to use ImplicitWait or ExplicitWaits. You can read about them here
You can try ExplicitWait to wait for the Passwd element:
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByName("signIn").click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")).sendKeys(""What ever");
driver.findElementByXPath("//*[#id='signIn']").click();
}
try with below code:
public void login() {
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.gmail.com");
driver.findElementById("Email").sendKeys("XXXXX#gmail.com");
driver.findElementByXPath("//*[#id='signIn']").click();
driver.findElementById("Passwd").sendKeys("XXXX");
driver.findElementByXPath("//*[#id='signIn']").click();
}
Add chrome driver capabilities
Try it once.
WebDriver driver = new ChromeDriver();
driver.get("https://www.gmail.com");
driver.manage().timeouts().impliciltyWait(30,TimeUnit.SECONDS);
driver.findElement(By.id("email-display").sendKeys("XXXXX#gmail.com");
driver.findElement(By.id("next"").click();
driver.findElement(By.id("Passwd")).sendKeys("xxxxxx");
driver.findElementByXPath("//*[#id='signIn']").click();

chromedriver.switchTo().frame(webview) crashes when testing a chrome app

I have a chrome app inside which there is a webview. To run functional tests, I need to click elements inside this webview but driver.switchTo().frame(webview) crashes with exception org.openqa.selenium.NoSuchFrameException.
Sample code :
System.setProperty("webdriver.chrome.driver", "/home/janindua/Software/chromeDriver/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/home/janindua/workspace/discovery-ui/scraper2/build/target/scraper.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
driver.get("chrome-extension://monoimhdfegpapbgppdmjfdgjdbkpboi/window.html");
driver.navigate().refresh();
driver.findElement(By.id("weburl-txtbox")).sendKeys("http://google.com/");
driver.findElementById("weburl-btn").click();
Thread.sleep(10000);
WebElement we = driver.findElementById("webv");
driver.switchTo().frame(we);
window html :
Stack trace :
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: no such frame: element is not a frame
(Session info: chrome=42.0.2311.135)
(Driver info: chromedriver=2.16.333243
(0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Linux 3.13.0-24-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'janindua', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_80'
Session ID: 878af1ba4a28469360756d6f786f6510
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.ZJ2D7R}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=42.0.2311.135, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
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:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:895)
at Google.main(Google.java:26)
janindu's answer is no longer correct (Partialy).
Since Oct 2015 there is a proper method to get webviews window handle
How to:
We will need to inform the driver that we want it to handler webviews window handlers
(The chromeOptions & windowTypes are the important parts)
It suppose to look something like this
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'windowTypes': ['webview']
}
},
After that, you can get the window handler in the usual way,
browser.getAllWindowHandles()
Right now this is a known bug, reported as Issue 960
If your chrome app uses a webview to load a web page and you want to run some automated scripts, chromedriver does not provide a method to access the elements in the web page loaded inside the webview.
Both chromedriver.switchTo().frame(webview) and chromedriver.switchTo().window(webview) methods will throw exceptions as webviews are not acceptable inputs to either method.

WebDriverBackedSelenium in Internet Explorer is not working

An error can be seen while running the test in Selenium, I have tried removing and adding the capabilities but in vain:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, url);
Thread.sleep(3000);
selenium.open(url);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
selenium.type("userId", "TEst");
The error is thrown because of the line selenium.type("userId", "TEst") and the error is as follows:
JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 81 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'slc05apo', ip: '10.241.115.70', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_26'
Session ID: 4368aa6a-ba4a-42a9-8428-1ce9a8f71dcc
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:39326/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
But no error can be seen if I use this:
WebDriver driver = new InternetExplorerDriver( DesiredCapabilities.internetExplorer());
driver.get(url);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.findElement(By.id("userId")).sendKeys("test");
But I want to use the first given case. Please help.
Whatever the capabilities you are setting, should be passed when instantiating the driver.
Please change this
WebDriver driver = new InternetExplorerDriver( DesiredCapabilities.internetExplorer());
to
WebDriver driver = new InternetExplorerDriver(capabilities);
Hope this works.