在 Linux 中使用 Python 模拟击键
我正在使用 Selenium 用 Python 编写一个脚本,自动填写 Web 表单(帮助台票务系统)
其中一个因素是票证正文没有 Selenium 识别的元素 id,因此为了输入正文我必须找到标题元素,按 Tab 键,然后开始在正文中输入。
这是一些将消息写入正文的代码:
der = "/t this is the desc"
driver.find_element_by_id("title").send_keys(der)
问题是,这段代码对我不起作用。我真正需要做的是这样的:
body = open(email.txt)
driver.find_element_by_id("title").send_keys("/t" + body)
所以我希望它找到 title 元素,按 Tab 键,然后将存储在 body 变量中的内容写入票证正文中。唯一的问题是语法不好。
我查看了 SendKeys 但这仅适用于 Windows。我正在使用 Fedora 16。
任何帮助/建议将不胜感激。
谢谢!
I am writing a script in Python using Selenium that auto fills out a web form (a helpdesk ticketing system)
A factor in this is the body of the ticket does not have an element id that Selenium recognizes, so in order to type in the body I have to find the title element, press the tab key, then start typing in to the body.
Here is some code that writes a message into the body:
der = "/t this is the desc"
driver.find_element_by_id("title").send_keys(der)
The problem is, this code doesnt work for me. What I really need to do would look like this:
body = open(email.txt)
driver.find_element_by_id("title").send_keys("/t" + body)
So I want it to find the title element, press the tab key, then write what is stored in the body variable into the body of the ticket. the only issue is that syntax is bad.
I looked at SendKeys but that is windows only. I am using Fedora 16.
Any help/recommendations would be greatly appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中有一个错误。将此:更改
为:
You have a bug in your code. Change this:
to: