python+selenium移动滑块代码【杭州多测师_王sir】【杭州多测师】
淘宝登录场景python+selenium移动滑块代码
#coding=utf-8 import time from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://www.taobao.com/") driver.implicitly_wait(1) account = 'account' # 账号 password = 'abc123' # 密码 driver.find_element(by=By.CSS_SELECTOR, value="div.member-ft > div > a.btn-login").click() driver.maximize_window() driver.implicitly_wait(1) driver.switch_to.window(driver.window_handles[1]) el_account = driver.find_element(by=By.CSS_SELECTOR, value='#fm-login-id') print(el_account.text) driver.implicitly_wait(1) el_account.click() el_account.send_keys(account) driver.implicitly_wait(1) el_password = driver.find_element(by=By.XPATH, value='//*[@id="fm-login-password"]') el_password.click() el_password.send_keys(password) driver.implicitly_wait(2) el_login_btn = driver.find_element(by=By.XPATH, value='//*[@id="login-form"]/div[4]/button') el_login_btn.click() # print(el_login_btn.location) driver.implicitly_wait(1) driver.switch_to.frame('baxia-dialog-content') el1 = driver.find_element(by=By.XPATH, value='//*[@id="nc_1_n1z"]') print(el1.size['width']) print(el1.size['height']) el2 = driver.find_element(by=By.XPATH, value='//*[@id="nc_1__scale_text"]') print(el2.size['width']) print(el2.size['height']) driver.implicitly_wait(2) chains = ActionChains(driver) chains.drag_and_drop_by_offset(el1, el2.size['width'], -el2.size['height']) chains.perform() time.sleep(5) driver.close() driver.quit()