简体   繁体   English

在硒脚本中找不到xpath元素

[英]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. 我正在尝试使用python-selenium脚本单击gmail主页右上角的“登录”标签。我曾使用firebug / firepath为该类找到正确的xpath,但似乎工作正常使用浏览器工具时,但是当脚本尝试使用xpath查找相同元素时失败。 I would greatly appreciate if you can point me to the right direction.Thank you! 如果您能指出正确的方向,将不胜感激。谢谢!

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

PS:I'm relative new to selenium . PS:我对硒还比较陌生。 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. 看起来像其他重定向到另一个URL,并使请求失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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