当前位置:网站首页>Three waiting methods of selenium and three processing methods of alert pop-up
Three waiting methods of selenium and three processing methods of alert pop-up
2022-07-27 05:22:00 【Si Xiaoyou】
Catalog
# Three waiting examples
from time import sleep
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
1. Set the loading policy of the page
options = webdriver.ChromeOptions()
options.page_load_strategy = 'none'
driver = webdriver.Chrome(options = options)
# driver.set_window_size(800,1000)
# driver.timeouts = ' Maximum timeout time '
2. An implicit wait
# Maximum waiting 5 The second time
driver.implicitly_wait(5)
sleep(5)
driver.get("http://39.98.138.157/shopxo/index.php")
driver.find_element('name','wd').send_keys(' mobile phone ')
# driver.get("http://www.baidu.com")
3. According to wait
# Waiting to arrive kw Is displayed , Then continue with the subsequent operations .
# Show waiting for specified elements , The maximum waiting time is 10 second , Every time 0.5 Once per second , Until the element is found , If not found, it shows message The content of , Throw an exception TimeOutException
# driver.find_element('id','kw').send_keys(' False bamboo ')
# driver.find_element('id','su').click()
# el = WebDriverWait(driver,2,0.5).until(lambda el1 : driver.find_element('xpath','//*[@id="1"]/div/div/h3/asda'),message=' Show wait failed ')
# temp = WebDriverWait(driver,10,0.5).until_not(lambda el1 : driver.find_element('xpath','//*[@id="1"]/div/div/h3/a'),message=' Show wait failed ')
4. Mandatory waiting
# Ignore all logic , Running to this step will force you to wait 2 Seconds .
# sleep(2)
# driver.find_element('xpath','//*[@id="1"]/div/div/h3/a').click()
# el.click()
# print(temp)
# driver.quit()
5. Three alert How to handle pop ups
from selenium import webdriver
driver = webdriver.Chrome()
1, Switch to pop-up window
alert = driver.switch_to.alert
2. confirm
alert.accept()
3. Cancel
alert.dismiss()
4. Input text
alert.send_keys(' Text entered ')
5. obtain alert Text information in pop-up window
text = alert.text
边栏推荐
- [optical flow] - data format analysis, flowwarp visualization
- 接收方设置并发量和限流
- The difference between strlen and sizeof
- JVM上篇:内存与垃圾回收篇五--运行时数据区-虚拟机栈
- B1027 print hourglass
- 消息可靠性处理
- The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
- 2022年郑州轻工业新生赛题目-打死我也不说
- JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
- JVM上篇:内存与垃圾回收篇十一--执行引擎
猜你喜欢

SQL数据库→约束→设计→多表查询→事务

辗转相除法

树莓派rtmp推流本地摄像头图像

JVM上篇:内存与垃圾回收篇二--类加载子系统

JVM Part 1: memory and garbage collection part 14 -- garbage collector

Could not autowire. No beans of ‘userMapper‘ type found.

弹球小游戏

Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time

文件处理(IO)

JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位
随机推荐
Critical path principle
[acwing] solution to the 61st weekly match
1、 MySQL Foundation
JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack
Prime number screening (Ehrlich sieve method, interval sieve method, Euler sieve method)
JVM Part 1: memory and garbage collection part 9 - runtime data area - object instantiation, memory layout and access location
JVM上篇:内存与垃圾回收篇二--类加载子系统
整合SSM
Bean's life cycle & dependency injection * dependency auto assembly
树莓派rtmp推流本地摄像头图像
34. 分析flexible.js
B1021 single digit statistics
Basic operation of vim
Solution to Dlib installation failure
Another skill is to earn 30000 yuan a month+
File processing (IO)
探寻通用奥特能平台安全、智能、性能的奥秘!
How to sinicize the JMeter interface?
JVM Part 1: memory and garbage collection part 3 - runtime data area - overview and threads
笔记系列之docker安装Postgresql 14