在 python 3 中是否有比 Selenium 的 send_keys 更快的替代方法?
Is there a faster alternative to Selenium's send_keys in python 3?
我已经自动化了一项任务,该任务是从文本文件中填写网络表单。该文本文件可能会变得很大,并且在 selenium + python3 中使用 send_keys() 函数需要相当长的时间。
是否有更快的替代方案,就像 copy/paste 的工作方式一样?
这就是我在脚本中使用它的方式:
reportFile = open(reportFilePath,'r')
for line in reportFile.read():
messageElem.send_keys(line)
reportFile.close()
我在网上看过,有替代品,但仅限于 JS。我正在寻找一种更快的方法来添加文件中的文本,特别是 python 3.
的确,Visweswaran Nagasivam 是正确的。我正在逐个字符地阅读文件。对我来说正确的方法是使用 readlines() 函数:
#open the report file
reportFile = open(reportFilePath,'r')
#iterate over each line of the report file and fill in the message body
for line in reportFile.**readlines**():
messageElem.send_keys(line)
#close the file
reportFile.close()
我已经自动化了一项任务,该任务是从文本文件中填写网络表单。该文本文件可能会变得很大,并且在 selenium + python3 中使用 send_keys() 函数需要相当长的时间。
是否有更快的替代方案,就像 copy/paste 的工作方式一样?
这就是我在脚本中使用它的方式:
reportFile = open(reportFilePath,'r')
for line in reportFile.read():
messageElem.send_keys(line)
reportFile.close()
我在网上看过,有替代品,但仅限于 JS。我正在寻找一种更快的方法来添加文件中的文本,特别是 python 3.
的确,Visweswaran Nagasivam 是正确的。我正在逐个字符地阅读文件。对我来说正确的方法是使用 readlines() 函数:
#open the report file
reportFile = open(reportFilePath,'r')
#iterate over each line of the report file and fill in the message body
for line in reportFile.**readlines**():
messageElem.send_keys(line)
#close the file
reportFile.close()