简体   繁体   中英

Unable to find xpath element in a selenium script

I'm trying to use python-selenium script to click on "Sign In" label on a top right corner of the gmail main page.I had used firebug/firepath to find the correct xpath for this class and it seems to be working fine while using browser tools but failed when scripts tries to find same element using xpath. I would greatly appreciate if you can point me to the right direction.Thank you!

Url: https://www.google.com/gmail/about/

PS:I'm relative new to selenium . So please excuse my ignorance if I'm approaching this issue in a wrong manner.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1920, 1080))
display.start()
browser = webdriver.Firefox()
browser.get('https://www.gmail.com')
print (browser.title)
g_login=browser.find_element_by_xpath("//a[@class='gmail-nav__nav-link gmail-nav__nav-link__sign-in']")
g_login.click()

You should use the same url you provide above in your post :

browser.get('https://www.google.com/gmail/about/')

Looks like the other redirects to another url and makes the request fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM