程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to use selenium to locate elements that cannot be located and report errors (Language Python)

編輯:Python

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
driver=webdriver.Chrome()
driver.get('https://kyfw.12306.cn/otn/resources/login.html')
driver.maximize_window()
huoqu=driver.find_element_by_xpath('//input[@placeholder=" user name / mailbox / cell-phone number "]').send_keys(")
huoqu=driver.find_element_by_xpath('//input[@placeholder=" password "and @aria-label=" Please input a password "]').send_keys(")
time.sleep(3)
driver.find_element_by_xpath('//a[@class="btn btn-primary form-block"]').click()

Select the node where you want to drag the slider

sli_ele = driver.find_element_by_xpath('//span[@id="nc_1_n1z" and @class="nc_iconfont btn_slide"]').click()
time.sleep(3)

Mouse sliding operation

action = ActionChains(driver)

First step : Press and hold the left mouse button at the slider

action.click_and_hold(sli_ele)

The second step : Move relative to the current position of the mouse

action.move_by_offset(0,300)

The third step : Release the mouse

action.release()

Executive action

action.perform()

driver.quit()


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved