如何实现 Python 中 selnium 模块的换行
三种方法:
直接调用 .submit() 方法,常使用在用户密码登录中
# driver.find_element_by_xpath('//*[@id="tree-finder-field"]').submit()
使用系统换行符,缺陷受限
# 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.
调用自带类,键盘模拟种类全
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://*.com/
该小技巧使用在lctt-cli项目