Program not executing fine- Selenium - selenium

I downloaded Selenium 2.53 version, now I have Selenium 3.2 version, both times same blank page opened, no URL . pls chk below error message.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AadminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("WebDriver.gecko.driver","C:/geckoDriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("Kawal");`
}
}
Build info: version: 'unknown', revision: '8c03df6', time: '2017-03-02 09:30:17 -0800'
System info: host: 'DESKTOP-BTAFHIV', ip: '192.168.153.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:293)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:122)
at abcd.AadminLogin.main(AadminLogin.java:12)

You need to change :
System.setProperty("WebDriver.gecko.driver","C:/geckoDriver.exe");
To :
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe");
In Selenium 3.x the Key-Value pair is expressed as webdriver.gecko.driver and C:/geckoDriver.exe

Try with updating code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AadminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe"); //Here changes are made
WebDriver driver= new FirefoxDriver();
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("Kawal");`
}
}
All other things are fine. it is just some casing issue in setProperty(). And for 2.53 there is no need of geckodriver

Related

Is InvalidArgumentException ensureCleanSession a known IEDriverServer 3.12.0 issue or am I instantiating it incorrectly?

When I attempt to instantiate IEDriverServer 3.12.0 like this:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class StartInternetExplorer {
public static void main(String[] args) {
// Add to Windows PATH variable: C:\IEDriverServer_Win32_3.12.0\;
String executable = "C:\\IEDriverServer_Win32_3.12.0\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", executable);
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com");
driver.quit();
}
}
I see this exception stack trace:
Started InternetExplorerDriver server (32-bit)
3.12.0.0
Listening on port 46039
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: All firstMatch elements failed validation
Invalid capabilities in firstMatch element 0: unknown capability named ensureCleanSession
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'XXXXXXXX', ip: '127.0.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
remote stacktrace:
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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
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:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:223)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:215)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
at app.StartInternetExplorer.main(StartInternetExplorer.java:11)
I don't know where the "ensureCleanSession" argument is coming from, so I don't know if this means there is a bug in 3.12.0 or if I am not instantiating IEDriverServer properly.
Tried passing 4 slashes in URL and it worked. Seems they have make some changes in selenium API but I am not sure. This worked for me:
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Money {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
InternetExplorerDriver driver=new InternetExplorerDriver();
driver.get("https:\\\\www.google.com");
}
}
I cannot replicate this in release 3.14.0 - The solution was to wait for a new release.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class StartInternetExplorer {
public static void main(String[] args) {
// Add to Windows PATH variable: C:\IEDriverServer_Win32_3.14.0\;
String executable = "C:\\IEDriverServer_Win32_3.14.0\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", executable);
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com");
driver.quit();
}
}

java.net.ConnectException: Failed to connect to localhost error with Selenium 3.11.0 with IEDriverServer and IE 11 on Windows 10

I am very new to selenium and trying to set up selenium in my laptop to begin. I am unable to invoke IE from my simple code. The details are given below. Can you please help me to understand where the issue is
IE version: IE 11,
IE Driver: 64-bit,
OS: Windows 10 64 bit,
Selenium version: 3.11
Error:
Started InternetExplorerDriver server (64-bit)
3.9.0.0
Listening on port 29313
Only local connections are allowed
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-B1D1PSJ', ip: '192.168.79.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:223)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:215)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:152)
at testing.Tryselenium.main(Tryselenium.java:31)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:101)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
... 6 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 okhttp3.internal.platform.Platform.connectSocket(Platform.java:125)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238)
Code:
mport java.util.Arrays;
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.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Tryselenium {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver web;
/*System.setProperty("webdriver.chrome.driver","C:\\Users\\Divakar\\Documents\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "chromedriver_x32.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("excludeSwitches",Arrays.asList("test-type"));
web = new ChromeDriver(chromeOptions);
web.manage().window().maximize();
web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
System.setProperty("webdriver.ie.driver","E:\\General\\Learnings\\Selenium\\Others\\Set Up files\\Browser Drivers\\" + "IEDriverServer.exe");
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
web = new InternetExplorerDriver();
web.manage().window().maximize();
web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);
/*FirefoxDriver web = new FirefoxDriver();
web = new FirefoxDriver();
web.manage().window().maximize();
web.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);*/
web.get("http://www.icicibank.com/");
web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/a[1]")).click();
web.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/div[3]/div/ul[1]/li[1]/a")).click();
web.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/div/div[1]/div/div[3]/a")).click();
web.findElement(By.name("AuthenticationFG.USER_PRINCIPAL")).sendKeys("507133118");
web.findElement(By.name("AuthenticationFG.ACCESS_CODE")).sendKeys("Soft2008");
web.findElement(By.name("Action.VALIDATE_CREDENTIALS")).click();
web.findElement(By.id("ContentLink1")).click();
WebElement accttable = web.findElement(By.xpath("/html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div"));
List<WebElement> all_rows = accttable.findElements(By.tagName("tr"));
int j = 0;
for (int i = 0; i < all_rows.size(); i++) {
List<WebElement> rowAllCells = all_rows.get(i).findElements(By.tagName("td"));
if(rowAllCells.size()>1)
{
String acctno=rowAllCells.get(2).getText();
if(rowAllCells.get(2).getText().trim().equalsIgnoreCase("602605049934"))
{
web.findElement(By.id("AccountSummaryFG.SELECTED_INDEX")).click(); ///html/body/form/div/div[3]/div[1]/div[4]/div[2]/div/div/div[5]/div/div/div/div/div/div/div/table/tbody/tr[4]/td[1]/input
web.findElement(By.id("HREF_actNicNameOutput[" + j + "]")).click();
web.findElement(By.id("backBtn")).click();
web.findElement(By.id("VIEW_MINI_STATEMENT")).click();
web.findElement(By.id("HREF_Logout")).click();
web.close();
}
else j = j + 1;
}
}
}
}
The error says it all :
3.9.0.0
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:29313
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-B1D1PSJ', ip: '192.168.79.96', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: driver.version: InternetExplorerDriver
It is clear from your error stack trace that the new session is not getting initiated and the driver.version is also not getting recognized.
Your main issue is the version compatibility between the binaries you are using as follows :
You are using Selenium Client v3.11.0
You are using IEDriverServer v3.9.0.0
You are using InternetExplorer v11.0 (as per your question)
So there is a clear mismatch between the Selenium Client v3.11.0 , IEDriverServer v3.9.0.0.
Solution
Upgrade IEDriverServer to v3.11.1.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
If your base Web Browser base version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Browser.
Execute your #Test.
Additional Considerations
You are using the flag INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true which is against the best practice. Don't do it.
This answer is updated for Edge Browser. If you are using Edge Browser and facing the same issue. Then follow the steps:
Download the latest IEDriverServer from this location : https://selenium.dev/downloads/
Update your code as follows :
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class SL001_OpenWebpage_Edge
{
public static void main(String[] args)
{
System.setProperty("webdriver.ie.driver", "\\location\\IEDriverServer.exe");
WebDriver driver=new EdgeDriver();
driver.get("https://www.hul.co.in/");
driver.findElement(By.id("tcm:1255-50553-4")).click();
//driver.manage().window().maximize();
}
}
The issue in our case was not specific to Jenkins but the Chrome Driver crashing under the VMs where our automation tests run.
If you log into your VM machine and where your workspace have been copied into, and under the terminal run the same maven command you have on Jenkins you should be able to watch the tests run and this may be a way for you to identify and fix the issue.
I had this occur even with the same Driver and client versions.
Started InternetExplorerDriver server (32-bit)
3.141.59.0
...
java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:XXXX
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'HOST_NAME', ip: 'XX.XXX.XX.XX', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: RemoteWebDriver
I ended up finding a perfect match here
http://selenium-release.storage.googleapis.com/index.html
but the Security Settings in IE were different and not correct on a new computer. Making each zone have the same Enable Protected Mode box state (every one selected or deselected) in
Internet Options -> Security
Fixed it 100%. Was getting the driver to launch and navigate to a page, but the prior two steps fixed the errors.

When I am trying run a simple selenium webdriver Application, then the following error occurs

public class FirstTest
{
public static void main(String[] args)
{
WebDriver driver =new FirefoxDriver();
driver.get("https://www.google.co.in/");
driver.close();
}
}
Note: Webdriver Java Language Bindings 3.3.1
**Error:**
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions#3c6f6d, version=, platform=ANY, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile#1eb8acf}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'RAJANIKANT', ip: '192.168.0.102', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
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.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:293)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:122)
at FirstTest.main(FirstTest.java:15)
If you are using WebDriver 3.3 or higher then you have to download the gecko driver .
This is the link to download the latest geckodriver.exe : Click here to download geckodriver
and then set system properties.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", **path to your geckodriver.exe**");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.co.in/");
driver.close();
}
}

Unable to enter ID in twitter

I'm running the below selenium code.
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class twitter {
public static void main(String[] args) throws InterruptedException {
FirefoxDriver fd = new FirefoxDriver();
fd.get("https://twitter.com/?lang=en");
Thread.sleep(2000L);
fd.findElement(By.xpath(".//*[#id='signin-email']")).sendKeys("Hello");
}
}
But i'm getting the below error.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 14 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'U0138039-TPL-A', ip: '192.168.1.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 96e0f5be-8e7d-402d-b7d0-2ebadc745663
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=40.0.3}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:273)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:94)
at twitter.main(twitter.java:10)
Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'U0138039-TPL-A', ip: '192.168.1.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:9982)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12626)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12643)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12648)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/u0138039/AppData/Local/Temp/anonymous8514896172902827974webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12590)
please let me know how can i fix it.
Thaks
The problem I ran into is when I navigated to the site myself, the login panel was showing but when I did the same thing with code, the login panel was not showing. The way to get around that is to click on the "Log In" button, then enter the username/password. The code below clicks the Log In button and enters the email and password
driver.get("https://twitter.com/?lang=en");
driver.findElement(By.cssSelector("button.StreamsLogin")).click();
driver.findElement(By.id("signin-email")).sendKeys("email");
driver.findElement(By.id("signin-password")).sendKeys("password");
EDIT: For those who can't see the Log In button??? This is what I see.
I tried with JavascriptExecutor as below and it worked! It fills user name and password as foo and bar and submits.
package org;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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;
public class TwitterTest {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// driver.manage().window().maximize();
// Go to the page
driver.get("https://twitter.com/?lang=en");
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#class='front-signin js-front-signin']")));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('signin-email').value = 'foo';");
js.executeScript("document.getElementById('signin-password').value = 'bar';");
js.executeScript("document.getElementsByClassName('t1-form signin')[0].submit();");
wait.wait(10);
driver.quit(); }
}

On perfect HTML, WebDriver gives a NoSuchElementException on the controls

I was trying to automate the Reset functionality in "http://www.efrotech.com/careers" for learning purposes. When I get the control locators I see it is perfect HTML that has almost all the locators; but when I try to run the script it is not recognizing the control and throwing painful NoSuchElement exception. Can you suggest what could be going wrong in that?
package com;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class ScriptChecker {
/**
* #param args
*/
public static WebDriver driver;
public static String baseUrl;
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
baseUrl = "http://www.efrotech.com";
driver.get(baseUrl +"/careers");
new Select(driver.findElement(By.id("ddlJobs"))).selectByVisibleText("QA Engineer");
driver.findElement(By.cssSelector("input#txtName")).sendKeys("Muzaffar");
System.out.println("Done here");
}
}
I have tried every locator but unable to manipulate the control state and its values.
Stacktrace followed:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"ddlJobs"}
Command duration or timeout: 10.07 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'muzaffar', ip: '192.168.0.161', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05'
Session ID: 206431fe-6770-4cbc-a60e-71fe92739807
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=25.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
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:595)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389)
at org.openqa.selenium.By$ById.findElement(By.java:214)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
at com.ScriptChecker.main(ScriptChecker.java:30)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"id","selector":"ddlJobs"}
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'muzaffar', ip: '192.168.0.161', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05'
Driver info: driver.version: unknown
at .FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/SMUZAF~1/AppData/Local/Temp/anonymous1906408348495286600webdriver-profile/extensions/fxdriver#googlecode.com/components/driver_component.js:8905)
at .fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/SMUZAF~1/AppData/Local/Temp/anonymous1906408348495286600webdriver-profile/extensions/fxdriver#googlecode.com/components/driver_component.js:396)
The drop down element which you are trying to use is under iFrames. Please switch to it and then proceed with your selection.
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[height='520']")));
new Select(driver.findElement(By.xpath(".//*[#id='ddlJobs']"))).selectByVisibleText("QA Engineer");
hope this solves.