如何实现 Python 中 selnium 模块的换行

如何实现 Python 中 selnium 模块的换行

三种方法:

  1. 直接调用 .submit() 方法,常使用在用户密码登录中

# driver.find_element_by_xpath('//*[@id="tree-finder-field"]').submit()

  1. 使用系统换行符,缺陷受限

# driver.find_element_by_xpath('//*[@id="tree-finder-field"]').send_keys('\r\n','\n')

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n"). You need to be careful about transferring files between Windows machines and Unix machines to make sure the line endings are translated properly.

  1. 调用自带类,键盘模拟种类全
from selenium.webdriver.common.keys import Keys
driver.find_element_by_xpath('//*[@id="login"]/form/div[4]/input[3]').send_keys(Keys.ENTER)

但是!不管使用哪种方法,都需要 time.sleep 让系统停下会,不然永远不生效(尤其是信息搜索的时候)

参考:
http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html
https://stackoverflow.com/

该小技巧使用在lctt-cli项目

转载于:https://www.cnblogs.com/itxdm/p/6883815.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值