Python+Selenium定位悬停元素总是报错,什么原因
1个回答
展开全部
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import os,time
driver=webdriver.Chrome()
driver.get("http://192.168.0.222:8085/zfgtaiAdmin/Product/loginBackground.jsp")
time.sleep(3)
#driver.maximize_window()
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("15112304365")
driver.find_element_by_id("username").send_keys(Keys.TAB)
time.sleep(4)
driver.find_element_by_id("password").send_keys("System.out.print")
driver.find_element_by_css_selector("input[type=\"button\"]").click()
driver.find_element_by_link_text("产品管理").move_to_element("产品管理").perform()
#WebDriverWait(driver,10).until(lambda the_driver)
WebDriverWait(driver,10).until(lambda the_driver:the_driver.find_element_by_link_text("产品管理").is_displayed())
menu= driver.find_element_by_link_text("产品管理").find_element_by_link_text("产品发布")
webdriver.ActionChains(driver).move_to_element(menu).perform()
time.sleep(5)
driver.quit()
Traceback (most recent call last):
File "E:\WorkSpace\Selenium 1\src\Test14__init__.py", line 22, in
driver.find_element_by_link_text("产品管理").move_to_element("产品管理").perform()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 317, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
(Session info: chrome=50.0.2661.102)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)
这是什么问题啊?
我认为是PYTHON2.7支持UNICODE的问题,建议采用PY3.0以后版本。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import os,time
driver=webdriver.Chrome()
driver.get("http://192.168.0.222:8085/zfgtaiAdmin/Product/loginBackground.jsp")
time.sleep(3)
#driver.maximize_window()
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("15112304365")
driver.find_element_by_id("username").send_keys(Keys.TAB)
time.sleep(4)
driver.find_element_by_id("password").send_keys("System.out.print")
driver.find_element_by_css_selector("input[type=\"button\"]").click()
driver.find_element_by_link_text("产品管理").move_to_element("产品管理").perform()
#WebDriverWait(driver,10).until(lambda the_driver)
WebDriverWait(driver,10).until(lambda the_driver:the_driver.find_element_by_link_text("产品管理").is_displayed())
menu= driver.find_element_by_link_text("产品管理").find_element_by_link_text("产品发布")
webdriver.ActionChains(driver).move_to_element(menu).perform()
time.sleep(5)
driver.quit()
Traceback (most recent call last):
File "E:\WorkSpace\Selenium 1\src\Test14__init__.py", line 22, in
driver.find_element_by_link_text("产品管理").move_to_element("产品管理").perform()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 317, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
(Session info: chrome=50.0.2661.102)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)
这是什么问题啊?
我认为是PYTHON2.7支持UNICODE的问题,建议采用PY3.0以后版本。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询