selenium元素定位问题
#coding=utf-8from selenium import webdriver
import time
dr=webdriver.Firefox()
dr.get("https://www.umeng.com/")
dr.find_element_by_link_text("登录").click()
print("点登录了")
#以下这两条报错定位不到元素
dr.find_element_by_id("fm-login-id").click()
dr.find_element_by_xpath("//input[@id='fm-login-id']").click()检查看不出来哪有问题,请大神们排查一下
Traceback (most recent call last):
File "D:/Test/python/c.py", line 13, in <module>
dr.find_element_by_id("fm-login-id").click()
File "C:\Users\Olivia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Users\Olivia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Olivia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Olivia\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
其一,我刚刚试着查看了你这个网站包含登录字样的位置,发现有两个,所以按照文本是无法定位的
其二,xpath定位的路径有误 如果有iframe表单,你要swtch_to_iframe进入才行 直接Xpath吧,应该是定位错误了 切换定位方式 换个元素id' 使用xpath 切换定位元素 定位错了把
页:
[1]