WebDriverBackedSelenium in Internet Explorer is not working - selenium

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.

Related

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

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).

How to use Alert box on button click in selenium by using web driver in java [duplicate]

This question already has answers here:
Alert handling in Selenium WebDriver (selenium 2) with Java
(5 answers)
Closed 6 years ago.
Please help me Tester, i am frustrated this point i have apply more and more code but no solution found again and same message show.
................................................................................
org.openqa.selenium.UnhandledAlertException: Unexpected modal dialog (text: Meal Added to Shopping List): Meal Added to Shopping List
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Saurabh', ip: '192.168.3.21', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 87eb9958-85a9-4571-8bbd-663fdaad2ad0
You can try this:
WebDriverWait wait = new WebDriverWait(driver, 3);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
Hope this helps!!

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();

protractor NoSuchElementError: no such element

When I was try to send keys in non-angular page with protractor it shows an error "NoSuchElementError: no such element"
NoSuchElementError: no such element
(Session info: chrome=47.0.2526.80)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 24 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'Sekhar-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_13'
* Element info: {Using=id, value=ius-userids}
Session ID: 352e36f285f80dee03eb5c88697ebc08
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\Sekhar\AppData\Local\Temp\scoped_dir3128_18281}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=47.0.2526.80, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
**
When testing non-Angular pages with Protractor, you need to include this line in all of your specs:
browser.ignoreSynchronization = true;
You also need to wait for the page to completely load. Using ExpectedConditions is one way to do that. Example:
var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable(element(by.css('.wait-for-me'))), 10000);
Use sleep condition.
browser.driver.sleep(500);
This will wait the browser for sometime.
Looks like timing issue, write some "expect" statements so that it will verify for particular functionality is available.
Try to use implicit wait.
Try writing your script in promises so that it will wait.
field.sendKeys(value).then(function(){
submitButton.click().then(function(){
expect('xyz').toBe(xyz);
});
});

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.