我想使用PhantomJS更改滑块手柄,但它不起作用。请检查以下可在Chrome Webdriver下运行但不在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