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?
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);
I am working with selenium webdriver with java.
The issue that I faced is Drag and drop not working with selenium 3 and firefox driver
I'm getting the below error:
org.openqa.selenium.UnsupportedCommandException: POST /session/92189939-94cc-4327-bfb0-72d66621d2f2/moveto did not match a known command
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'TADT063', ip: '192.168.0.195', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_20'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\Amrutha.U\AppData\Local\Temp\rust_mozprofile.l2Myb7jgbekD, rotatable=false, timeouts={implicit=0, page load=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=52.0, platformVersion=6.1, moz:processID=4308, browserName=firefox, platformName=windows_nt}]
Session ID: 92189939-94cc-4327-bfb0-72d66621d2f2
Can anybody help me?
Code :
public void selectQuestions() throws InterruptedException, AWTException {
Thread.sleep(3000);
WebElement selectquestions = webElement("VAR_SELECTTOP5QUESTIONS");
selectquestions.click();
Thread.sleep(10000);
Actions builder = new Actions(driver);
Action drag = builder.clickAndHold(webElement("VAR_SELECTQUESTIONS")).build();
drag.perform();
Point coordinates = webElement("VAR_SELECTEDQUESTIONS").getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX() + 280, coordinates.getY() + 120);
Thread.sleep(3000);
WebElement questions = webElement("VAR_SELECTEDQUESTIONS");
questions.click();
Thread.sleep(1000);
WebElement questionNextButton = webElement("VAR_QUESTION_NEXTBUTTON");
questionNextButton.click();
Thread.sleep(1000);
}
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?
package erewards2;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
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;
public class login_sib2 {
public static void main(String[] args) {
FirefoxDriver d1 = new FirefoxDriver();
d1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
d1.get("https://sib3.erewardsredeem.com/fm/customer.html?action=userLogin");
d1.manage().window().maximize();
WebElement e4 = d1.findElementByLinkText("Login");
e4.click();
d1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement e1 = d1.findElement(By.id("showmemberid"));
e1.sendKeys("2800000091");
WebElement e2 = d1.findElementById("showmemberpwd");
e2.sendKeys("Miquser1");
WebElement e3 = d1.findElementByClassName("loginbtn");
e3.click();
WebElement e5 = d1.findElementByLinkText("Logout");
e5.click();
Alert a1 = d1.switchTo().alert(); //web based alert
WebDriverWait wait = new WebDriverWait(d1,10);
wait.until(ExpectedConditions.alertIsPresent()).accept();
a1.accept();
System.out.println("test1");
//close Firefox
d1.close();
System.out.println("test2");
// exit the program explicitly
System.exit(0);
System.out.println("test3");
}
}
I added the system.out println lines for test purpose and found that My code did not able to execute completely from Test1 statement. Below is the exception I got on my Eclipse IDE.
Exception in thread "main" org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13.82 seconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'pcs-PC', ip: '192.168.1.64', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 59fe366a-5fdc-4763-a6f2-0860bf1378be
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=30.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:526)
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:595)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:610)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteAlert.accept(RemoteWebDriver.java:910)
at erewards2.login_sib2.main(login_sib2.java:40)
It looks like it fails before it gets to the close statement.
Try structuring your code like this:
FirefoxDriver d1 = new FirefoxDriver();
try {
// steps
}
finally {
d1.close();
}
This will guarantee the close statement is executed.
You can try using d1.quit() too.
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());
}
}
}