Selenium将鼠标光标移动到Firefox中不工作的元素
================================Selenium将鼠标光标移动到Firefox中不工作的元素,selenium,selenium-webdriver,automation,webdriver,automated-tests,Selenium,Selenium Webdriver,Automation,Webdriver,Automated Tests,================================ #!/usr/bin/env python # -*- coding: utf-8 -*- from selenium.webdriver.common.by import By import selenium.webdriver as webdriver import time firefox = webdriver.Firefox() firefox.get("http://www.baidu.com") inp
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium.webdriver.common.by import By
import selenium.webdriver as webdriver
import time
firefox = webdriver.Firefox()
firefox.get("http://www.baidu.com")
input = firefox.find_element_by_id("kw")
action = webdriver.ActionChains(firefox)
action.send_keys_to_element(input, "testvalue")
action.perform()
#This step (move mouse to "input" element) NOT work! :(
action = webdriver.ActionChains(firefox)
action.move_to_element(input)
action.perform()
time.sleep(3)
firefox.quit()
操作系统:Win7
硒:2.33.0
Firefox:22.0
Python:2.7.4
================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium.webdriver.common.by import By
import selenium.webdriver as webdriver
import time
firefox = webdriver.Firefox()
firefox.get("http://www.baidu.com")
input = firefox.find_element_by_id("kw")
action = webdriver.ActionChains(firefox)
action.send_keys_to_element(input, "testvalue")
action.perform()
#This step (move mouse to "input" element) NOT work! :(
action = webdriver.ActionChains(firefox)
action.move_to_element(input)
action.perform()
time.sleep(3)
firefox.quit()
我想用“move_to_element”方法将鼠标光标移动到元素“input”上,但无法执行此操作
有人有这个问题吗
================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium.webdriver.common.by import By
import selenium.webdriver as webdriver
import time
firefox = webdriver.Firefox()
firefox.get("http://www.baidu.com")
input = firefox.find_element_by_id("kw")
action = webdriver.ActionChains(firefox)
action.send_keys_to_element(input, "testvalue")
action.perform()
#This step (move mouse to "input" element) NOT work! :(
action = webdriver.ActionChains(firefox)
action.move_to_element(input)
action.perform()
time.sleep(3)
firefox.quit()
问题解决了。我认为move_to_element()方法应该将真正的鼠标光标移动到对象上。但是selenium不会让鼠标悬停而不移动真正的鼠标光标。谢谢 尝试了你的代码。你的意思是什么不起作用?你预计会发生什么 当你将鼠标悬停在百度的输入上时,没有视觉效果。Selenium在不移动真实鼠标的情况下移动到元素,因此您不会看到真实鼠标光标的位置变化 如果您真的想测试
将元素移动到元素中,请针对具有悬停效果的对象进行测试,以便您可以直观地看到它
下面是一个例子:
#/usr/bin/env python
#-*-编码:utf-8-*-
从selenium.webdriver.common.by导入
将selenium.webdriver导入为webdriver
导入时间
firefox=webdriver.firefox()
firefox.get(“http://stackoverflow.com/tags")
tags=firefox.find_elements_by_css_selector(“#tags browser.tag cell.post tag”)
action=webdriver.ActionChains(firefox)
操作。将\u移动到\u元素(标记[0])
action.perform()
谢谢!这是我的错。我认为它应该将鼠标光标移动到它。现在没事了。:)谢谢这是我的错。我认为它应该将鼠标光标移动到它。现在没事了。:)