selenium webdriver:提交后表单数据不存在
我有一个页面,我可以在其中登录然后填写一些表格。提交第一个表单后,会出现一个包含新表单的新页面。有些数据是从之前的表格中获取的(应该如此),但有些数据丢失了。
如果我手动执行与 webdriver 完全相同的操作,则一切正常,并且表单 1 中的所有数据都存在于表单 2 中。
代码非常简单:
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("http://www.example.com")
### login ###
driver.find_element_by_id("UserName").send_keys("foo")
driver.find_element_by_id("Password").send_keys("bar")
driver.find_element_by_id("LoginButton").click()
# fill first form and submit
driver.find_element_by_id("Info").send_keys("data")
driver.find_element_by_id("info2").send_keys("data2")
driver.find_element_by_id("Submit").click()
# new page where "data" should be present but isn't
# ...
我做错了什么?
我想我可能必须使用cookies?如果是这样,我该如何使用它们?刚刚找到 C# 示例,不知道从哪里导入 Cookie 类。
I have a page in which I log in and then fill in some forms. After submitting the first form, a new page appears with new forms. Some data is taken from the forms before (as it should be), but some data is missing.
If I do exactly the same I do with webdriver by hand, everything works fine and all the data from form 1 is present in form 2.
The Code is pretty simple:
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("http://www.example.com")
### login ###
driver.find_element_by_id("UserName").send_keys("foo")
driver.find_element_by_id("Password").send_keys("bar")
driver.find_element_by_id("LoginButton").click()
# fill first form and submit
driver.find_element_by_id("Info").send_keys("data")
driver.find_element_by_id("info2").send_keys("data2")
driver.find_element_by_id("Submit").click()
# new page where "data" should be present but isn't
# ...
What am I doing wrong?
I thought I may have to use cookies? If so, how do I use them? Just found C# examples and don't know where to import the Cookie class from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
访问本教程的 cookie 部分
http://readthedocs.org/docs/selenium-python/en/latest /navigating.html
Visit the cookie section of this tutorial
http://readthedocs.org/docs/selenium-python/en/latest/navigating.html