当前位置:网站首页>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
边栏推荐
- Database connection pool & Druid usage
- JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack
- 来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
- File processing (IO)
- Interface and abstract class / method learning demo
- LocalDateTime和ZonedDateTime
- Bean的生命周期&&依赖注入*依赖自动装配
- The difference between strlen and sizeof
- Set static IP for raspberry pie
- 听过最自律的一句话: 那些我难以言表 不作声响
猜你喜欢

JVM上篇:内存与垃圾回收篇九--运行时数据区-对象的实例化,内存布局与访问定位

JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack

35. Scroll

2021 OWASP top 4: unsafe design

2、 MySQL advanced

JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area

素数筛选(埃氏筛法,区间筛法,欧拉筛法)

A math problem cost the chip giant $500million

如何快速有效解决数据库连接失败问题

Prime number screening (Ehrlich sieve method, interval sieve method, Euler sieve method)
随机推荐
B1029 旧键盘
JVM Part 1: memory and garbage collection part 3 - runtime data area - overview and threads
Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
枚举类实现单例模式
来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education
JVM上篇:内存与垃圾回收篇二--类加载子系统
B1021 个位数统计
Could not autowire.No beans of ‘userMapper‘ type found.
Detailed explanation of pointer constant and constant pointer
Demo of throttling function -- regular expression matching
Solution and principle analysis of feign call missing request header
2021 OWASP top 5: security configuration error
JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack
传智教育|软件测试工程师未来的发展方向有哪些?
Summary of knowledge points (I)
JDBC API 详解
Scientific Computing Library -- Matplotlib
ERROR! MySQL is not running, but PID file exists
B1025 reverse linked list*******