在使用 Selenium 操作 Web 浏览器 按钮滑动时 报错:
selenium.common.exceptions.WebDriverException: Message: unknown command: Cannot call non W3C standard command while in W3C mode
解决方法:在创建 driver 对象时,添加浏览器的 option 选项 关闭 w3c 模式
from selenium import webdriver
import time
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.common.by import By
# selenium.common.exceptions.WebDriverException: Message: unknown command: Cannot call non W3C standard command while in W3C mode
opt =webdriver.ChromeOptions()
opt.add_experimental_option('w3c',False)
driver = webdriver.Chrome(options=opt)
driver.maximize_window()
driver.get("https://open.captcha.qq.com/online.html")
print(driver.window_handles)
print(driver.current_window_handle)
driver.find_element_by_id("code").click()
time.sleep(2)
driver.switch_to.frame("tcaptcha_iframe")
print(driver.window_handles)
print(driver.current_window_handle)
time.sleep(1)
ac = TouchActions(driver)
drag_thumb = driver.find_element_by_id("tcaptcha_drag_thumb")
ac.scroll_from_element(drag_thumb, 100, 0).perform()
time.sleep(1)
|