-2

我需要有关 python 的帮助...您知道单击按钮登录后如何检查 Web 浏览器的响应(此处:提交)吗?如果我的登录成功,我想比较 html 代码并返回 True 但不幸的是我不知道如何。:/ 任何提示都是无价的。:) 那是我来自 selenium 的代码:

driver.find_element_by_css_selector("input.username").send_keys("margie")
driver.find_element_by_css_selector("input.password").clear()
driver.find_element_by_css_selector("input.password").send_keys("margie")
driver.find_element_by_css_selector("div.btn.submit").click()

我可以使用“如果”吗?

谢谢你们的时间!

4

1 回答 1

0

You can just continue using driver after clicking on submit button. For example, driver.page_source would contain the html code of the page displayed after the login.

There is no universal silver bullet to check if the login was successful or not. It depends on the web-site you are testing against: it may redirect to a particular url, have certain elements on the web page, certain title etc.


Just a side note. If you would follow Page Object pattern/concept, you would have a separate object for Login Page and a separate object for the page displayed after the login aka Home Page - like in this example. The actual page look check after the login would be incapsulated inside the Home Page object realization which would make things clearer and better organized.

See also:

于 2014-08-13T14:46:03.277 回答