I am randomly getting an org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. error, i.e., it doesn't always happen with the same input in the same code. The code:
public class PortalListingCallable implements Callable<Listing> {
private WebDriver driver;
private WebElement event;
public PortalListingCallable(WebElement event) {
driver = new HtmlUnitDriver();
this.event = event;
}
public Listing call() {
//System.out.println("in PortalLisingCallable");
Listing newListing = ListingFactory.createListing(
new PortalScheduleEventsEvent(driver, event.findElements(By.tagName("td"))).parse());
driver.close();
return newListing;
}
}
I have also tried the line Listing newListing = ListingFactory.createListing(new PortalScheduleEventsEvent(new HtmlUnitDriver(), event.findElements(By.tagName("td"))).parse());
This class implements Callable, so it's being called by multiple threads, but the data is independent. That code:
while (webElementsQueue.peek() != null) {
Callable<Listing> callable = new
PortalListingCallable(webElementsQueue.poll());
//Future<Listing> future = executor.submit(callable);
Future<Listing> future = executor.submit(new Callable<Listing>() {
#Override
public Listing call() throws Exception {
try {
return callable.call();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
});
listingQueue.offer(future);
}
I suspect that this has something to do with this being called in multiple threads, but since each instance of HtmlUnitDriver is isolated, I'm not sure how.
Below is the exception:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:269)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:188)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:265)
at org.openqa.selenium.By$ByTagName.findElements(By.java:324)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:164)
at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:31)
at autoschedtwo.portal.PortalListingCallable.call(PortalListingCallable.java:17)
at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:40)
at autoschedtwo.portal.PortalDriver$1.call(PortalDriver.java:36)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
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)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Build info: version: '2.46.0', revision: '61506a4624b13675f24581e453592342b7485d71', time: '2015-06-04 10:22:50'
System info: host: '955PC', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:76)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
... 13 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:26014 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:67)
... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 27 more
Related
I'm trying to run a test using Opera browser as a node, hub and node connections are succesful.
Below is for hub and node connections:
Hub > java -jar selenium-server-standalone-3.9.1.jar -role hub
Node > java -Dwebdriver.opera.driver=C:\zip\exe\operadriver_win64\operadriver_win64\operadriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://192.168.1.10:4444/grid/register -port 5566
When trying to executing the program two Opera browser loads but only blank white pages shown with Not secure data:; on URL and I am also getting this kind of exception.
org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Opera driver and Opera Browser I'm using:
Opera Version: 82.0.4227.58
Opera Driver Version : 96.0.4664.45
Below is the code used:
package Grid;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class OperaNode {
static WebDriver driver;
String nodeUrl;
#SuppressWarnings("deprecation")
#BeforeTest
public void OpenBrowser() throws InterruptedException {
try {
nodeUrl = "http://192.168.1.10:5566/wd/hub";
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
driver.manage();
driver.get("http://www.yahoo.com");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
#Test
public void SigninButton() throws InterruptedException {
try {
driver.findElement(By.xpath("//a[#class='_yb_duqkn']")).click();
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
#AfterTest
public void CloseBrowser() {
driver.quit();
}
}
Below is the console Message:
FAILED CONFIGURATION: #BeforeTest OpenBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
Command duration or timeout: 1.94 seconds
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
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.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
at Grid.OperaNode.OpenBrowser(OperaNode.java:36)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:637)
at org.testng.TestRunner.beforeRun(TestRunner.java:627)
at org.testng.TestRunner.run(TestRunner.java:589)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from org.openqa.selenium.remote.NewSessionPayload#6153fbda
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-KML9RV5', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.2'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:75)
at java.util.Optional.orElseThrow(Optional.java:403)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:74)
at java.util.Optional.orElseGet(Optional.java:364)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:72)
at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:242)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.lang.Thread.run(Thread.java:831)
The RemoteWebDriver url configuration should always be routed to the hub, if using the Selenium Grid setup as your browser stack. The hub will then check for a node which matches your browser request and forward onto that node.
nodeUrl = "http://<hub ip address>:4444/wd/hub";
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
package automationFramework;
import java.awt.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.lang.IllegalStateException;
public class Second_Practise {
public static void main(String[] args) throws InterruptedException {
String URL = "https://accounts.google.com/signin";
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.14.0-win64\\geckodriver.exe");
driver =new FirefoxDriver();
driver.get(URL);
WebElement Email = driver.findElement(By.id("identifierId"));
Email.sendKeys("dialogspp");
WebElement Next = driver.findElement(By.id("identifierNext"));
Next.click();
Thread.sleep(2000);
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[#id='password']/div[1]/div/div[1]/input")));
WebElement Password = driver.findElement(By.xpath(".//*[#id='password']/div[1]/div/div[1]/input"));
Password.sendKeys("dialogapp");
WebElement PassNext = driver.findElement(By.id("passwordNext"));
PassNext.click();
Thread.sleep(2000);
//WebElement gmail = driver.findElement(By.xpath("//a[#href='https://mail.google.com']"));
WebElement myDynamicElement2 = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#href='https://mail.google.com']")));
myDynamicElement2.click();
Thread.sleep(2000);
WebElement myDynamicElement3 = (new WebDriverWait(driver, 10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#gh='cm']")));
myDynamicElement3.click();
}
}
I am using this piece of code to send an email, but on clicking "Compose" button i am getting the exception. i.e.
Jun 20, 2017 2:57:37 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.xpath: //div[#gh='cm'])
org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //div[#gh='cm']
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'ANUM-PC', ip: '172.16.11.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
at java.util.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:234)
at automationFramework.Second_Practise.main(Second_Practise.java:35)
Exception in thread "main" org.openqa.selenium.JavascriptException: Error: Permission denied to access property "navigator"
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'ANUM-PC', ip: '172.16.11.162', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20161031133903, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.2, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop, firefox_profile=UEsDBBQACAgIACp31EoAAAAAAAAAA...}]
Session ID: b216dfb9-b672-4cd2-b7cc-087c74789afa
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:315)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:302)
at org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:234)
at automationFramework.Second_Practise.main(Second_Practise.java:35)
I am able to access the element using firepath but error is still been there. Any suggestions?
I try to execute this script:
public class BuyMenShirt {
public static void main(String[] args) throws InterruptedException
{
//Firefox driver setup
String driverPath = "C:\\Users\\RW\\geckodriver-master\\";
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.gap.com");
WebElement menlink = driver.findElement(By.id("division5063"));
menlink.click();
WebElement shirtlink = driver.findElement(By.cssSelector("a.sidebar-navigation--category--link[href=/browse/category.do?cid=15043]"));
shirtlink.click();
}
}
However, I got this error:
Nov 01, 2016 2:10:13 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript error: http://www.gap.com/, line 20471: TypeError: personalizationService.model.personalizationData.personalizationInfoV1.featureSelections is null
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'RW-PC', ip: '192.168.0.105', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20161019084923, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=1692, browserVersion=49.0.2, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}]
Session ID: 9c166d1b-3391-4ed9-8fac-3afe6d09b13f
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:465)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:430)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
at BuyMenShirt.main(BuyMenShirt.java:27)
Caused by: java.lang.IllegalArgumentException: expected one element but was: <org.openqa.selenium.remote.ErrorCodes$KnownError#cd2dae5, org.openqa.selenium.remote.ErrorCodes$KnownError#4973813a>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:322)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:284)
at org.openqa.selenium.remote.ErrorCodes.toStatus(ErrorCodes.java:138)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:92)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
... 5 more
Did I do something wrong? I notice I got some JavaScript error right before UnreachableBrowserException. Does it matter?
I am trying to write a word in google search editbox and capture all the related list item and display it. But while doing so i got Got a exception
org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions. I went through the same exception related question and according to them changed my code but none of them help.
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class AutoIt {
public static void main(String[] args){
WebDriver window;
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(false);
window = new FirefoxDriver(profile);
try{
window.get("https://www.google.co.in/");
window.manage().window().maximize();
window.findElement(By.id("gs_htif0")).sendKeys("Shantanu Nandan");
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
List<WebElement> list=window.findElements(By.xpath("//td[#style='width: 100%;']/span"));
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
for(WebElement data:list){
System.out.println(data.getAttribute("value"));
}//for
}//try
catch(Exception e){
System.out.println("Got a exception");
e.printStackTrace();
window.close();
}//catch
finally{
System.out.println("Finally Block Executed ....");
window.close();
window.quit();
}//finally
}//main
}//class
Exception which i got for this code
org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions
Command duration or timeout: 47 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
Session ID: d29ef567-95a8-47ce-bf84-c510cbb2756d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=29.0.1}]
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:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at AutoIt.main(AutoIt.java:21)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is disabled and so may not be used for actions
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.enabled(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:8185)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10814)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10831)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10836)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js:10778)
Finally Block Executed ....
You have selected the wrong element.
Use the below one for search text box
wb=window.findElement(By.name("q"));
Use the below for getting output suggestions.
List<WebElement> list = window.findElements(By.className("gsq_a"));
To get the values from the list, use getText() method instead of getAttribute().
for (WebElement data : list) {
System.out.println(data.getText());
}
Please try the below code
public class AutoSuggest {
WebDriver driver;
#Before
public void seup()
{
driver= new FirefoxDriver();
}
#Test
public void test_autosuggest()
{
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in/");
driver.findElement(By.xpath("//div[#id='gs_lc0']//input[#id='gbqfq']")).sendKeys("h");
WebElement wb=driver.findElement(By.xpath("//td[#class='gssb_e']"));
List<WebElement> links= wb.findElements(By.tagName("div"));
System.out.println("the total "+links.size());
for (int i=0;i<links.size();i++)
{
System.out.println(links.get(i).getText());
}
}
}
static WebDriver driver = new FirefoxDriver();
public static void main(String[] args) throws IOException, InterruptedException {
// TODO code application logic here
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter base url....!!!");
String baseurl = br.readLine();
connection c= new connection();
c.makeConnection(driver,baseurl);
JavascriptExecutor js;
if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
js.executeScript("alert('hello world');");
}
Following error occurs
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present: hello world
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'comp74', ip: '192.168.0.74', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_17'
Session ID: f6ba3a2b-87d4-4192-ad1a-94cf260d8f6e
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=26.0}]
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:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.createUnhandledAlertException(ErrorHandler.java:174)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:332)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:408)
at org.openqa.selenium.By$ByXPath.findElements(By.java:358)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:295)
at javaapplication4.count.linkCount(count.java:27)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:34)
Is per my understanding. After executing an alert if you try to do any other operation in the page when the alert already exists this errors comes. Are you providing the actual code?
Exception shows
at javaapplication4.count.linkCount(count.java:27)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:34)
as per above stacktrace you do something in linkCount.
If you have anycode after .executeScript("alert('hello world' line. Please comment them and then check.