gmail using selenium driver in eclipse

+4 votes
package CoreJava;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Tutorials1 {

public static void main(String[] args) {

// System.setProperty("webdriver.chrome.driver",

// "C:\\Users\\everybody\\Desktop\\selenium\\library\\chromedriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("https://www.gmail.com");

driver.findElement(By.id("identifier")).sendKeys("solomonfan1990");

driver.findElement(By.className("Next")).click();

driver.findElement(By.className("password")).sendKeys("ertyuir");

driver.findElement(By.className("Next")).click();

}

}

The above code gave me the following error. i am trying to use the className on the new version of gmail

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"identifier"}

Command duration or timeout: 684 milliseconds

For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'

System info: host: 'LAPTOP-0BTLVCK6', ip: '192.168.17.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'

Driver info: org.openqa.selenium.firefox.FirefoxDriver

Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=36.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

Session ID: f500dd0c-fcc1-427d-873c-a189c183a730

*** Element info: {Using=id, value=identifier}

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: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 CoreJava.Tutorials1.main(Tutorials1.java:16)

Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"identifier"}

For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'

System info: host: 'LAPTOP-0BTLVCK6', ip: '192.168.17.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'

Driver info: driver.version: unknown

at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/EVERYB~1/AppData/Local/Temp/anonymous1783806094359282166webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10271)

at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/EVERYB~1/AppData/Local/Temp/anonymous1783806094359282166webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10280)

at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/EVERYB~1/AppData/Local/Temp/anonymous1783806094359282166webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12274)

at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/EVERYB~1/AppData/Local/Temp/anonymous1783806094359282166webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12279)

at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/EVERYB~1/AppData/Local/Temp/anonymous1783806094359282166webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12221)
Sep 11, 2018 in Selenium by fan
• 190 points
102 views
There is a mismatch in your logic...you need to call geckodriver.exe
More details in my answer below.

2 answers to this question.

+4 votes
Best answer

@letslearn, it seems like you have tried using chromedriver.exe for performing the test. Below line is what you have in your code.

// System.setProperty("webdriver.chrome.driver",

// "C:\\Users\\everybody\\Desktop\\selenium\\library\\chromedriver.exe");

For some strange reason, you have commented out these two lines above. system.setProperty() function is highly essential line if you want to run your test and it is used to chose a particular browser on which the test will be performed...

Moreover, in your entire code, you have wanted to perform the test on Firefox (Gecko), but you've set property for chromedriver.exe as it is evident from above. 

Soln:- 

Download geckodriver.exe from seleniumhq.org and provide the path to gecko driver in the above line of code..

Let me know if it works for you :) Happy learning :) 

answered Sep 11, 2018 by Vardhan
• 12,200 points

selected Sep 11, 2018 by Omkar
0 votes

Try using this:

driver.get("https://www.gmail.com");
WebElement id = driver.findElement(By.id("identifierId"));
id.sendKeys("priyajkumart");
WebElement button = driver.findElement(By.className("CwaK9"));
button.click();
Thread.sleep(5000);
WebElement password = driver.findElement(By.name("password"));
password.sendKeys("mypassword");
WebElement button1 = driver.findElement(By.className("CwaK9"));
button1.click();

This worked fine for me. Hope it helps you too!

answered Dec 20, 2018 by Priyaj
• 56,200 points

Related Questions In Selenium

0 votes
1 answer

Login page test script using selenium and java in Eclipse IDE

Here is an example to login to ...READ MORE

answered Apr 23, 2018 in Selenium by Meci Matt
• 9,400 points
2,332 views
+9 votes
14 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,250 points
53,283 views
0 votes
2 answers

Get text using selenium web driver in python

text = driver.find_element_by_class_name("current-text").getText(); READ MORE

answered Feb 4 in Selenium by anonymous
9,212 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
406 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
762 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
402 views
+6 votes
1 answer

Recording all of our test cases in Selenium IDE

Well @vincitydaimo, for obvious reasons we prefer not ...READ MORE

answered Sep 20, 2018 in Selenium by Vardhan
• 12,200 points
59 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 12,200 points
172 views