求助:Selenium3+python2.7,定位不到元素(报错:NoSuchElementException)

求助:Selenium3+python2.7,定位不到元素(报错:NoSuchElementException)

最近在自学web自动化测试,使用selenium3+Python2.7,Chrome浏览器,测试百度账号注册时遇到定位不到元素的问题。
代码如下:

#coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome(r"C:\Program Files\Google\Chrome\Application\ChromeDriver.exe") 
driver.get("https://www.baidu.com/")
#获取当前窗口句柄
search_windows = driver.current_window_handle
element = driver.find_element_by_link_text("登录")
element.click()
time.sleep(3)
driver.find_element_by_link_text("立即注册").click()

运行结果如下:
求助:Selenium3+python2.7,定位不到元素(报错:NoSuchElementException)_第1张图片

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\windows.py", line 19, in 
    element1.find_element_by_link_text(u'立即注册').click()
  File "D:\python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 241, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "D:\python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 654, in find_element
    {"using": by, "value": value})['value']
  File "D:\python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "D:\python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "D:\python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: chrome=69.0.3497.100)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.1.7601 SP1 x86)

修改代码如下后,效果和上面一样:

#coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome(r"C:\Program Files\Google\Chrome\Application\ChromeDriver.exe") 
driver.get("https://www.baidu.com/")
#获取当前窗口句柄
search_windows = driver.current_window_handle
element = driver.find_element_by_link_text("登录")
element.click()
time.sleep(3)
element1 = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_4__title"]')
time.sleep(3)
element1.find_element_by_link_text(u'立即注册').click()

恳请哪位大神帮忙解答下,感谢~~

你可能感兴趣的:(求助:Selenium3+python2.7,定位不到元素(报错:NoSuchElementException))