JaverScript有个内置对象:arguments。包含函数调用的参数数组,[0]表示取对象第一个值。currentSrc:返回当前音频、视频的URL
load(): 控制视频加载;play(): 控制视频播放; pause():控制视频暂停。
from time import sleep from selenium import webdriver driver = webdriver.Chrome() driver.get("http://videojs.com/") video = driver.find_element_by_id("preview-player_html5_api") url = driver.execute_script("return arguments[0].currentSrc;", video) print(url) print("start") driver.execute_script("arguments[0].play()", video) sleep(15) print("stop") driver.execute_script("arguments[0].pause()", video) driver.quit()
滑动解锁:click_and_hold(): 单击并按下鼠标左键;move_by_offset();移动鼠标,第一个参数为x坐标距离,第二个参数为Y坐标距离;resrt_action() :重置action
from selenium import webdriver
from time import sleep
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
driver.get("https://www.cnblogs.com/")
driver.implicitly_wait(100)
driver.find_element_by_link_text("登录").click()
#用户名
driver.find_element_by_id("mat-input-0").send_keys("###")
#密码
driver.find_element_by_id("mat-input-1").send_keys("####")
#登录按键
driver.find_element_by_class_name("mat-button-wrapper").click()
#滑块
slider_button = driver.find_element_by_class_name("geetest_slider_button")
action = ActionChains(driver)
#单击并按下鼠标左键
action.click_and_hold(slider_button).perform()
for i in range(200):
#移动鼠标:第一个参数为x轴坐标,第二个为Y轴
action.move_by_offset(10,0).perform()
#重置
action.reset_actions()
sleep(0.1)
滑动条:jQuery。以下代码复制到记事本,save as .html文件
<form method="post" action="demoform.php">
<label for="points">进度:</label>
<input type="range" name="points" id="points" value="50" min="0" max="100">
</form>
from selenium import webdriver from time import sleep from selenium.webdriver import ActionChains driver = webdriver.Chrome() url = "file:///C:/Users/Administrator/Desktop/hua.html" driver.get(url) sleep(2) slider = driver.find_element_by_id("points") action = ActionChains(driver) action.drag_and_drop_by_offset(slider,-100,0).perform()