当前位置:网站首页>Selenium uses -- XPath and analog input and analog click collaboration
Selenium uses -- XPath and analog input and analog click collaboration
2022-07-25 12:39:00 【Smell and break bamboo】
List of articles
Purpose
The main purpose of this article is to use xpath、 Analog input and analog click collaboration , As follows :
- Open the baidu , Search for CSDN
- Get into CSDN, Search for selenium Use ———xpath Cooperate with analog input and analog click This article .
- Click to enter this article to view
Search for CSDN
Open the baidu
browser.get("https://www.baidu.com/")
Enter in the input box CSDN
Find the input box . Right click the input box first , Enter check mode ; Next, right click the corresponding HTML Code , choice Copy->Copy XPath, Finally get XPath.
With XPath after , have access to Selenium Positioning , And fill in the contents that need to be input .
browser.find_element_by_xpath('//*[@id="kw"]').send_keys("CSDN")
Click the search button
Use the above steps to find the button XPath Value , And simulate clicking
browser.find_element_by_xpath('//*[@id="su"]').click()
Get into CSDN
Judge whether the page is loaded
Select the element you want to click in the page id, And judge whether the web page is loaded . Here I use the page id by content_left The element of is used to determine whether the component I need to click is loaded
print(" Start loading ")
Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "content_left")))
print(" End of load ")
After getting the information that the component to be clicked is loaded , Use the above steps to find CSDN Web page XPath Value , And click into
browser.find_element_by_xpath('//*[@id="1"]/div/div[1]/h3/a[1]').click()
from CSDN Search for articles on the homepage
Determine whether the required part is loaded
print(" Start loading ")
Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "toolbar-search-button")))
print(" End of load ")
Enter the information and click search
browser.find_element_by_xpath('//*[@id="toolbar-search-input"]').send_keys("selenium Use ———xpath Cooperate with analog input and analog click ")
browser.find_element_by_xpath('//*[@id="toolbar-search-button"]').click()
Enter the article and scroll
print(" Start loading ")
Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "post-1562")))
print(" End of load ")
# # Pull directly to the end
# js = 'window.scrollTo(0, document.body.scrollHeight)'
# browser.execute_script(js)
# Pull slowly
js = "return action=document.body.scrollHeight"
new_height = browser.execute_script(js)
for i in range(0,new_height,10):
browser.execute_script('window.scrollTo(0, %s)'%(i))
All the code
Somewhat chaotic
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as Wait
import time
# Initialize browser
browser = webdriver.Chrome()
# # Use Baidu search CSDN
# browser.get("https://www.baidu.com/")
# # Find the input box and type
# browser.find_element_by_xpath('//*[@id="kw"]').send_keys("CSDN")
# # Find the button and click
# browser.find_element_by_xpath('//*[@id="su"]').click()
# # Get into CSDN
# print(" Start loading ")
# Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "content_left")))
# print(" End of load ")
# browser.find_element_by_xpath('//*[@id="1"]/div/div[1]/h3/a[1]').click()
# # stay CSDN Search for specified articles
# print(" Start loading ")
# Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "toolbar-search-button")))
# print(" End of load ")
# browser.find_element_by_xpath('//*[@id="toolbar-search-input"]').send_keys("selenium Use ———xpath Cooperate with analog input and analog click ")
# browser.find_element_by_xpath('//*[@id="toolbar-search-button"]').click()
# browser.get('https://so.csdn.net/so/search?spm=1000.2115.3001.4501&q=aa&t=&u=')
# print(" Start loading ")
# Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "app")))
# print(" End of load ")
# browser.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div[1]/div[2]/div/div[1]/div/div[1]/h3').click()
browser.get('http://www.selenium.org.cn/1562.html')
print(" Start loading ")
Wait(browser, 60).until(EC.presence_of_element_located((By.ID, "post-1562")))
print(" End of load ")
# # Pull directly to the end
# js = 'window.scrollTo(0, document.body.scrollHeight)'
# browser.execute_script(js)
# Pull slowly
js = "return action=document.body.scrollHeight"
new_height = browser.execute_script(js)
for i in range(0,new_height,10):
browser.execute_script('window.scrollTo(0, %s)'%(i))
# browser.quit()
边栏推荐
- 水博士2
- 吕蒙正《破窑赋》
- Script set random user_ agent
- 推荐系统-协同过滤在Spark中的实现
- 2022 Henan Mengxin League game (3): Henan University I - Travel
- Pytorch advanced training skills
- 想要做好软件测试,可以先了解AST、SCA和渗透测试
- [fluent -- example] case 1: comprehensive example of basic components and layout components
- Interviewer: "classmate, have you ever done a real landing project?"
- 状态(State)模式
猜你喜欢

JS convert pseudo array to array

Kyligence was selected into Gartner 2022 data management technology maturity curve report

Cmake learning notes (II) generation and use of Library

More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural

通信总线协议一 :UART

MySQL exercise 2

WPF project introduction 1 - Design and development of simple login page
![[micro service ~sentinel] sentinel degradation, current limiting, fusing](/img/60/448c5f40af4c0937814c243bd7cb04.png)
[micro service ~sentinel] sentinel degradation, current limiting, fusing
Software testing interview question: Please list the testing methods of several items?

第一个scrapy爬虫
随机推荐
【六】地图框设置
1.1.1 welcome to machine learning
Jenkins配置流水线
【四】布局视图和布局工具条使用
Script set random user_ agent
[rust] reference and borrowing, string slice type (& STR) - rust language foundation 12
cmake 学习使用笔记(二)库的生成与使用
Detailed explanation of flex box
搭建Vision Transformer系列实践,终于见面了,Timm库!
Leetcode 0133. clone diagram
[fluent -- example] case 1: comprehensive example of basic components and layout components
If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
Perf performance debugging
交换机链路聚合详解【华为eNSP】
Does MySQL have flush privileges
JS convert pseudo array to array
What is ci/cd?
【二】栅格数据显示拉伸色带(以DEM数据为例)
More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现