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
1,182 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
• 13,190 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
• 58,090 points

Related Questions In Selenium

0 votes
1 answer

unable to launch my first code in eclipse using selenium chrome driver

@klbret, can you share your code or ...READ MORE

answered Oct 10, 2019 in Selenium by Abha
• 28,140 points
1,333 views
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,460 points
13,219 views
+10 votes
17 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,360 points
193,699 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, 2019 in Selenium by anonymous
37,609 views
0 votes
2 answers

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,500 points
12,576 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,558 views
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,910 points
6,603 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,506 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
• 13,190 points
662 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
• 13,190 points
15,264 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP