Not able to login

80 views
Skip to first unread message

Sapana Devani

unread,
Aug 19, 2016, 9:33:28 AM8/19/16
to seleniu...@googlegroups.com
Hello,

i am learning automation script using web driver

when i run gmail login script in Firefox it opens first Skype extension page & then connect to gmail 

login screen & after entering email it is stopped can anyone help me??


below is my script

package gmailpkg;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class gmailcls {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//  Wait For Page To Load
// Put a Implicit wait, this means that any search for elements on the page
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
// Navigate to URL
driver.get("https://mail.google.com/");
// Maximize the window.
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.id("Email")).sendKeys("email id");
// Enter Password
driver.findElement(By.id("Passwd")).sendKeys("password");
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
//Click on Compose Mail.
driver.findElement(By.xpath("//div[@class='z0']/div")).click();
// Click on the image icon present in the top right navigational Bar
driver.findElement(By.xpath("//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a")).click();
//Click on 'Logout' Button
driver.findElement(By.xpath("//*[@id='gb_71']")).click();
//Close the browser.
driver.close();
}
}



this is error code



Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a"}
Command duration or timeout: 60.10 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'sapana-d', ip: '192.168.10.125', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=42.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 233f8355-f36a-4feb-9967-080f17cb4406
*** Element info: {Using=xpath, value=//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a}
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:422)
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.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:445)
at org.openqa.selenium.By$ByXPath.findElement(By.java:358)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
at gmailpkg.gmailcls.main(gmailcls.java:30)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'sapana-d', ip: '192.168.10.125', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdr...@googlecode.com/components/driver-component.js:10667)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdr...@googlecode.com/components/driver-component.js:623)

Aniket Mane

unread,
Aug 19, 2016, 10:06:02 AM8/19/16
to seleniu...@googlegroups.com

Hi Sapana,
1.No need to use implicit wait multiple times,declare it only once in a script.
It automatically use that delay after each driver statement.
2. For error there may be two possibilities
A.After clicking compose mail button the focus get changed to compose box so clicking on that image won't be possible.
B.xpath or css you selected might be wrong.


at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:10667)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:623)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAL4jT3uP-JKDTGg4e6oa%3DpTzhhE_RaWnn0AwcESQ_PAYVV7Xag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

A.phani chakravarthy

unread,
Aug 19, 2016, 3:35:46 PM8/19/16
to Selenium Users
Hii Sapana. After clicking on sign in button use explicit wait or thread.sleep(10000) once mail page opence then focus will be shifted to compose button

Shawn McCarthy

unread,
Aug 20, 2016, 10:55:40 AM8/20/16
to Selenium Users
Gmail is generally really hard to automate. If you just need practice , http://the-internet.herokuapp.com/ might be a better option.
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:10667)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:623)

Sumeet

unread,
Aug 21, 2016, 1:58:54 AM8/21/16
to seleniu...@googlegroups.com
You might look at below website as well. Very useful specially made to automate



user name and password for 2nd website is admin  /  demo123

at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10667)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:623)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Sumeet Tambi

Ajay Goenka

unread,
Aug 22, 2016, 2:14:46 AM8/22/16
to Selenium Users
//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a

1. Make sure this ID is fixed and its not changing on every hit to while login.
2. Before clicking on any element make sure that element is present in that page 
3. Can you let me know the version of firefox and selenium ?

Thanks & Regards,
Ajay Goenka

prasanna sarathi

unread,
Aug 23, 2016, 10:36:31 PM8/23/16
to Selenium Users
From the way i look, the following lines are not static xpath's it will dynamically

driver.findElement(By.xpath("//div[@class='z0']/div")).click();
// Click on the image icon present in the top right navigational Bar
driver.findElement(By.xpath("//div[@class='gb_1 gb_3a gb_nc gb_e']/div/a")).click();
//Click on 'Logout' Button
driver.findElement(By.xpath("//*[@id='gb_71']")).click();

thumb rule is not to use a xpath that contain numbers(ex z0 or gb_71) in case of your above xpath
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:10667)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous8412394525810302914webdriver-profile/extensions/fxdri...@googlecode.com/components/driver-component.js:623)

Reply all
Reply to author
Forward
0 new messages