如果用户已经注册,如何签入Python Selenium?(马根托云)
初始情况: 目前,我在我们的项目中定义了几个测试用例,包括Magento云环境中的登录和注销 我目前使用Chrome Webdriver进行此测试 Python和最新的Selenium版本 问题情况: 我想检查用户是否已经注册 到目前为止我拥有的: 我目前正在检查用户是否想要登录,如果是相应的用户“Frank”,则会触发断言 但我相信有更好的解决办法如果用户已经注册,如何签入Python Selenium?(马根托云),python,selenium,selenium-webdriver,webdriverwait,expected-condition,Python,Selenium,Selenium Webdriver,Webdriverwait,Expected Condition,初始情况: 目前,我在我们的项目中定义了几个测试用例,包括Magento云环境中的登录和注销 我目前使用Chrome Webdriver进行此测试 Python和最新的Selenium版本 问题情况: 我想检查用户是否已经注册 到目前为止我拥有的: 我目前正在检查用户是否想要登录,如果是相应的用户“Frank”,则会触发断言 但我相信有更好的解决办法 def test_login(self): driver = self.driver time.sleep(1
def test_login(self):
driver = self.driver
time.sleep(10)
driver.find_username = wait.until(EC.presence_of_element_located((By.XPATH,'//span[contains(text(), "Frank")]')))
assert find_username
问题
在Python/Selenium中是否有更合理的解决方案来查询此问题 你很接近。您需要使用
visibility\u of \u element\u located()
,而不是使用presence\u of \u element\u located()
,您可以使用以下选项:
是否要验证错误消息是否显示且是否包含frank?如果此答案/任何答案对您有帮助,请为将来的读者投票。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
def test_login(self):
try:
driver.find_username = wait.until(EC.visibility_of_element_located((By.XPATH,'//span[contains(., "Frank")]')))
print("User was found")
assert find_username
except TimeoutException:
print("User wasn't found")