Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 为什么ActionChains在PhantomJS Webdriver中不起作用,但在Chrome Webdriver中起作用?_Python 2.7_Selenium Webdriver_Webdriver_Phantomjs_Selenium Chromedriver - Fatal编程技术网

Python 2.7 为什么ActionChains在PhantomJS Webdriver中不起作用,但在Chrome Webdriver中起作用?

Python 2.7 为什么ActionChains在PhantomJS Webdriver中不起作用,但在Chrome Webdriver中起作用?,python-2.7,selenium-webdriver,webdriver,phantomjs,selenium-chromedriver,Python 2.7,Selenium Webdriver,Webdriver,Phantomjs,Selenium Chromedriver,我想使用PhantomJS更改滑块句柄,但它不起作用。请检查以下在ChromeWebDriver下工作但在PhantomJS中不工作的代码。这些代码尝试向右滑动滑块宽度10%的手柄。 有没有办法让它为PhantomJS工作 from browsermobproxy import Server from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.supp

我想使用PhantomJS更改滑块句柄,但它不起作用。请检查以下在ChromeWebDriver下工作但在PhantomJS中不工作的代码。这些代码尝试向右滑动滑块宽度10%的手柄。 有没有办法让它为PhantomJS工作

from browsermobproxy import Server
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains

# settings for choosing Chrome or PhantomJS:
#...
#...
#driver = webdriver.Chrome(...) or webdriver.PhantomJS(...)

url = "http://jqueryui.com/slider/"
driver.get(url)
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME, "iframe")))

handle_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#slider > span")))
bar_element = driver.find_element_by_css_selector("#slider")
offset = bar_element.size['width'] * 0.1

print "Initial handle location:", handle_element.get_attribute("style")

move = ActionChains(driver)
move.click_and_hold(handle_element).move_by_offset(offset, 0).release().perform()

print "Handle location after sliding:", handle_element.get_attribute("style")

print "Slider bar size:", bar_element.size['width']
驱动程序为Chrome时的输出:

Initial handle location: left: 0%;
Handle location after sliding: left: 10%;
Slider bar size: 548
驱动程序为PhantomJS时的输出:

Initial handle location: left: 0%;
Handle location after sliding: left: 0%;
Slider bar size: 444

PhantomJS不支持本机拖动。你将不得不尝试合成事件

但是,对于“mousemove”,没有按下任何按钮(即,它没有拖动)


如果页面上有jQuery,可以通过
driver.execute\u script()
尝试类似的方法。是ruby的一个例子。

@ArtjomB。谢谢你的评论。我是初学者。那么,你能告诉我什么是“合成事件”吗?很抱歉,没有收到你的通知,因为我删除了我的评论并将其作为答案。如果页面上有jQuery,您可以尝试通过
driver.execute_script()
和JS native:@User执行类似的操作,这正是我所说的“合成事件”的意思。当问题被标记为python时,您还提供了一个指向ruby的链接