I'm trying to automate certifications online but it is preventing me from clicking on a link to proceed to the form page.
I've used the other solutions given by others and went from not able to finding the element to getting org.openqa.selenium.ElementNotInteractableException:
Here's a snippet of my code
List<WebElement> linkList = driver.findElements(By.tagName("a"));
for(int i = 0; i < linkList.size(); i++){
System.out.println(linkList.get(i).getAttribute("href"));
if(linkList.get(i).getAttribute(("href")).contains("student")){
linkList.get(i).click();
}
}
Basically I used the loop to find which tagName contained the link I needed, but here's the error:
Jul 11, 2017 7:49:21 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
org.openqa.selenium.ElementNotInteractableException:
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-35FGBMU', ip: '192.168.1.117', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\pizza\AppData\Local\Temp\rust_mozprofile.Heg8gMUCnERq, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=54.0.1, platformVersion=10.0, moz:processID=7448.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: 322f496f-033f-4ccf-a0ab-324182e773b3
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:82)
at com.Certify.startCertify(Certify.java:53)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
I've also never seen anyone with ElementNotInteractableException, but a similar variant of it that is similar (I think)
"Element is not currently interactable and may not be manipulated"
Here's the relevant HTML:
<li class="list label"
Manage My Students
</li>
Any help would be appreciated
EDIT: Found a way to go around it by using
driver.navigate().to(String.valueOf(linkList.get(i).getAttribute("href")));
But would really like to know how to do it properly as I don't think this is the way.
Assumption 1: There are some hidden links. You have to skip them by checking isDisplayed().
List<WebElement> linkList = driver.findElements(By.tagName("a"));
for(int i = 0; i < linkList.size(); i++){
System.out.println(linkList.get(i).getAttribute("href"));
if(linkList.get(i).getAttribute(("href")).contains("student") && linkList.get(i).isDisplayed()){
linkList.get(i).click();
}
}
Assumption 2: Some elements are being render on top of some links. You have to wait until they are clickable.
List<WebElement> linkList = driver.findElements(By.tagName("a"));
for(int i = 0; i < linkList.size(); i++){
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
System.out.println(linkList.get(i).getAttribute("href"));
if(linkList.get(i).getAttribute(("href")).contains("student")){
try {
wait.until(ExpectedConditions.elementToBeClickable(linkList.get(i));
linkList.get(i).click();
} catch (Exception e) {
System.out.println("Unable to click on " + linkList.get(i).getAttribute("href") + ". Exception: " + e.printStackTrace());
}
}
}
Related
I am getting the all too common connection refused error on my selenium webdriver. The same code was executing a few weeks ago.
I have been reading in circles through existing posts and have tried updating geckodriver and FireFox to no avail. I can run the same code on another computer running the same versions of the driver, browser and libraries etc. How can I find the cause specific to this machine? the error is below.
Debug 1
Debug 2
Debug 3
Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:28379 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'LT9LTDRC2', ip: '10.130.3.15', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131' Driver info: driver.version: Gecko_Driver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137) at seleniumPrograms.Gecko_Driver.main(Gecko_Driver.java:13)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:28379 [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:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:343)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) ... 8 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ... 23 more
And I get this running even the following basic code.
enter code here
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Gecko_Driver {
public static void main(String[] args) {
System.out.println("Debug 1");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
System.out.println("Debug 2");
capabilities.setCapability("marionette", true);
System.out.println("Debug 3");
WebDriver driver = new FirefoxDriver(capabilities);
System.out.println("Debug 4");
driver.get("http://www.google.com");
driver.manage().window().maximize();
driver.quit();
}
}
Example with chrome.
#Test
public void testGoogleSearch() throws InterruptedException {
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
Failure trace:
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'LT9LTDRC2', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: Gecko_Driver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:184)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:171)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124)
at seleniumPrograms.Gecko_Driver.testGoogleSearch(Gecko_Driver.java:16)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:31675/status] to be available after 20002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:107)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:190)
... 33 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:140)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:80)
... 34 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:128)
... 35 more
Our security dept introduced a policy which blocked access to the execution of the geckodriver.exe. This was identified by attempting to run from cmd. Not sure why I didn't get the meaningful error in the IDE (blocked by group policy) for gecko, I did get this error for chrome and IE. In order to use the driver it needed to be saved in Program files though this may be specific to my situation. If you get this error for Geckodriver i would suggest trying to execute it from cmd to see if there is a policy issue.
Here is the solution to your Question:
I don't see any error as such in your code but the error stack trace HttpHostConnectException says it all.
Perform the following steps:
I don't see any necessity to use throws InterruptedException, you may consider to remove it.
As per best practices try to keep the geckodriver in convenient locations: e.g. C:\\your_directory.
Avoid using directory names with Temp.
Though you have taken help of DesiredCapabilities Class, you haven't passed it while you initiated the driver instance. You must be doing:
WebDriver driver = new FirefoxDriver(capabilities);
Clear your Mozilla Firefox Browser cache.
From the Windows Task Manager, manually kill all the running instances of geckodriver.exe
You may require to run the CCleaner to keep off all the unwanted stuff.
Restart you machine.
Execute your Test. It should work well.
At the end of your Test Step do call driver.quit() to prevent geckodriver instances from dangling.
Here is your own working code block adding the System.setProperty line:
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
System.out.println("Debug 1");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
System.out.println("Debug 2");
capabilities.setCapability("marionette", true);
System.out.println("Debug 3");
WebDriver driver = new FirefoxDriver(capabilities);
System.out.println("Debug 4");
driver.get("http://www.google.com");
driver.manage().window().maximize();
driver.quit();
Let me know if this helps you.
I was facing the same error here. After a system reboot, the code worked just fine.
My problem was that my code left some processes open at the end, and they were using a lot of RAM.
Try running:
pkill geckodriver
pkill firefox
pkill selenium
And then run your code again.
I'm having a problem adding and deleting cookies with the native SafariDriver in Safari 10.0: A generic WebDriverException is thrown and I'm looking for a fix or a workaround.
This is occurring with the following components:
Mac OS X 10.11.6 (El Capitan)
Safari 10.0 [provides native implementation of SafariDriver]
Selenium 3.0.1
The following document indicates that the native SafariDriver in Safari 10 no longer requires installation of the Selenium SafariDriver extension, but depends on Selenium 3.0 or higher. And I've ensured that Selenium 3.x is being used and that Selenium 2.x is not on my system.
While testing, the browser window has the orange SmartSearch field, and throws the exception below when clicking the test window. I know the test framework is using the correct audio driver because of the following system property,and the fact that the exception thrown indicates the Selenium version as 3.0.1
The webdriver.safari.driver Mac OS X system property is set to /usr/bin/safaridriver
The following works with Safari:
driver.manage().getCookies();
The following fails with Safari, but works with Chrome
driver.manage().addCookie(cookie);
driver.manage().deleteAllCookies();
Exception stack trace for addCookie()
DEBUG [main] (DefaultNavigator.java:201) - Caught exception:
org.openqa.selenium.WebDriverException: An unknown server-side error
occurred while processing the command. (WARNING: The server did not
provide any stacktrace information) Command duration or timeout: 4
milliseconds
Build info: version: '3.0.1', revision: '1969d75',
time:'2016-10-18 09:49:13 -0700' System info: host: 'L-C02S61GDxxxx', ip:
'192.168.47.xxx, os.name: 'Mac OS X', os.arch: 'x86_64', os.version:
'10.11.6', java.version: '1.8.0_112
Driver info:
org.openqa.selenium.safari.SafariDriver Capabilities
[{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true,
handlesAlerts=true, version=11602.3.12.0.1, cleanSession=true,
platform=MAC, nativeEvents=true, locationContextEnabled=false,
webStorageEnabled=true, browserName=safari, javascriptEnabled=true,
cssSelectorsEnabled=true}] Session ID:
7513DEE7-DB0F-4CBD-B21E-D760C69880DB
DEBUG [main] (AbstractTest.java:91) - ###### Executing test: testSignInSuccess
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: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.RemoteWebDriver$RemoteWebDriverOptions.addCookie(RemoteWebDriver.java:718)
...
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.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
This was a known issue in safaridriver. It is fixed in Safari 11.
I'm getting "StaleElementReferenceException" when selecting an option from the dropdown and get it as string. I'm very disappointed with the issue for last two days and I didn't get any best suggestion to sort out my issue. I'm very new to selenium, Please help me to sort out this issue.
public static WebElement prepProduct(WebDriver driver) throws InterruptedException
{
WebDriverWait wait = new WebDriverWait(driver,20);
Boolean enable=driver.findElement(By.xpath(".//*[#id='batch-update-prep-owner']")).isEnabled();
if(enable.TRUE)
{
Select whoPrepsMerchant= new Select(driver.findElement(By.xpath(".//*[#id='prep-items']/tr[2]/td[5]/select")));
whoPrepsMerchant.selectByIndex(new Random().nextInt(whoPrepsMerchant.getOptions().size()));
String merchant=whoPrepsMerchant.getFirstSelectedOption().getText();
Thread.sleep(3000);
String whoPrepsvalue=(driver.findElement(By.xpath(".//*[#id='prep-items']/tr[2]/td[7]/span"))).getText();
System.out.println("outer");
if(merchant.equalsIgnoreCase("Amazon"))
{
System.out.println("inner");
if(!whoPrepsvalue.equalsIgnoreCase("--"))
{
System.out.println("innerone");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
}
else
{
if(whoPrepsvalue.equalsIgnoreCase("--"))
{
System.out.println("innertwo");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
}
}
else
{
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='continue-plan']")).click();
}
return element;
}
Error Log:
org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
Command duration or timeout: 15 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:29:23 -0700'
System info: host: '7531HY1', ip: '10.45.183.77', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.4.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 2eb3cd2b-e2e0-4efb-8b4c-3eb08f00ed45
*** Element info: {Using=tag name, value=option}
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:636)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:203)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByTagName(RemoteWebElement.java:280)
at org.openqa.selenium.By$ByTagName.findElements(By.java:327)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:179)
at org.openqa.selenium.support.ui.Select.getOptions(Select.java:70)
at org.openqa.selenium.support.ui.Select.getFirstSelectedOption(Select.java:94)
at NAGamma.SellerCentralPOM.prepProduct(SellerCentralPOM.java:85)
at NAGamma.Regression.main(Regression.java:40)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:607)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
at org.testng.SuiteRunner.run(SuiteRunner.java:270)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1096)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:29:23 -0700'
System info: host: '7531HY1', ip: '10.45.183.77', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9531)
at <anonymous class>.Utils.getElementAt(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:9916)
at <anonymous class>.FirefoxDriver.prototype.findElementsInternal_(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:11205)
at <anonymous class>.FirefoxDriver.prototype.findChildElements(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:11226)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12698)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12703)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/kesavamp/AppData/Local/Temp/anonymous980588199586178216webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12645)
Try this
Declare at the global level
WebDriverWait wait = new WebDriverWait(driver, 5);
Before selecting option from Drop-down
// while the following loop runs, the DOM changes -
// page is refreshed, or element is removed and re-added
wait.until(presenceOfElementLocated(By.id("container-element")));
// now we're good - let's click the element
For selecting option from Drop-down.
driver.findElement(By.id("foo")).click();
You can use:
wait.until(ExpectedConditions.refreshed(ExpectedConditions.visibilityOf(Element)));
Please verify and let me know if this is working fine for you...
I am doing Selenium Webdriver automation using Java.
Please find the attached HTML extract of a web page http://1drv.ms/1CMtRxd and find the UI of the same http://1drv.ms/1JzXarv.
From the html, understand that all UI elements are constructed within a Table and the issue identified here is, unable to find the elements which are present in Right hand side table.
However, there is no issue on locating and using the elements present on left-hand side table within automation scripts.
Could you advise what is the difference between these two tables and why I’m unable to find the elements of Right hand side table during playback.
Also, could someone kindly help me to resolve this issue, please.
Please find the code extract:
(Coded with Page Object Model)
In POM Class:
#Test(description = "Test to Track the Order")
public void searchOrder() throws Exception
{
SearchRequest searchReq = PageFactory.initElements(wd, SearchRequest.class);
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
searchReq.enterTrackingID("161471");
searchReq.clickSearchButton();
}
In Page Factory Class:
public class SearchRequest
{
#FindBy(how = How.ID, using = "cpportal:searchByID")
public WebElement trackingID;
public void enterTrackingID(String trackingID)
{
this.trackingID.clear();
this.trackingID.sendKeys(trackingID);
}
#FindBy(how = How.NAME, using = " cpportal:j_idt56 ")
public WebElement search;
public void clickSearchButton()
{
this.search.click();
}
}
Exception Thrown:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cpportal:searchByID"}
Command duration or timeout: 10.12 seconds
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-27 00:00:10'
System info: host: 'inl-279930-1', ip: '10.13.136.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
*** Element info: {Using=id, value=cpportal:searchByID}
Session ID: 3c404b65-ba64-435d-8395-53c262eff602
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=37.0.2}]
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:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:393)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:37)
at com.sun.proxy.$Proxy8.clear(Unknown Source)
at com.cgi.hqn.liveref.pageobjects.SearchRequest.enterTrackingID(SearchRequest.java:17)
at com.cgi.hqn.liveref.test.CreateSOSL.searchOrder(CreateSOSL.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cpportal:searchByID"}
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-27 00:00:10'
System info: host: 'inl-279930-1', ip: '10.13.136.53', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/SUBRAM~1/AppData/Local/Temp/anonymous5667416437314785176webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10271)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/SUBRAM~1/AppData/Local/Temp/anonymous5667416437314785176webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:603)
This could be an ajax element. Element is visible after a while.
What is the return value of-:
trackingID.isDisplayed();
This could be avoided by Implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
or by WebDriver wait
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(trackingID));
Hope that helps
I am trying to test my website with Selenium on Safari using Eclipse Luna.
My website uses Login with Twitter.
When I try to send key to an input on api.twitter.com I have a timeout.
Note that I have already tried "send keys" on google using the wiki page of Selenium even on www.twitter.com and it is working fine.
I do not understand why it is not working on api.twitter.com.
I thought the problem was my website, then I tested the same code on another website also using twitter authentication and I had the same error.
I even tried using javascriptExecutor to fill the value of the input and I also had a time out.
Could anyone please help me?
Please find below my code and the trace I have in my console.
package com.fxlabs.wonderboard.nodeTest;
import static org.junit.Assume.assumeTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
#RunWith(JUnit4.class)
public class BrowserTest {
private WebDriver driver = null;
private static boolean isSupportedPlatform() {
Platform current = Platform.getCurrent();
return Platform.MAC.is(current) || Platform.WINDOWS.is(current);
}
#Before
public void createDriver() {
assumeTrue(isSupportedPlatform());
driver = new SafariDriver();
}
#After
public void quitDriver() {
driver.quit();
}
#Test
public void shouldBeAbleToPerformAGoogleSearch() {
driver.get("http://tweetbeam.com");
new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("TweetBeam Twitter Wall - Visualize Live Tweets"));
driver.findElement(By.className("navbar-right")).findElement(By.tagName("a")).click();
new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("Twitter / Autoriser une application"));
driver.findElement(By.id("username_or_email")).sendKeys("TwitterUsername");
driver.findElement(By.id("username_or_email")).sendKeys("password");
}
}
Failure Trace:
org.openqa.selenium.TimeoutException: Timed out awaiting response to command "sendKeysToElement" after 30001 ms (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.01 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.6.0_65'
Session ID: null
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{platform=MAC, cssSelectorsEnabled=true, javascriptEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=7.1.4}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
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:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at com.fxlabs.wonderboard.nodeTest.BrowserTest.shouldBeAbleToPerformAGoogleSearch(BrowserTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
You're trying to send the email and password to the same field there aren't you?
driver.FindElement(By.Id("username_or_email")).SendKeys("TwitterUsername");
driver.FindElement(By.Id("password")).SendKeys("password");
This works fine for me.
However be careful as the page behaves differently if it detects you are logged in to twitter already. You get a popup with some dialog welcoming you.