当用户输入不正确的用户名和密码时,我试图获取文本“ Invalid Credentials”(放置在页面(js)上)。
login_button.click()
self.driver.implicitly_wait(10) # seconds
get_conformation_message = self.driver.find_element(By.XPATH, '//*[@id="toast-container"]/div/div[1]')
noz.assert_equal(get_conformation_message.text, "Incorrect Credentials")
我将等待时间设置为10秒,以确保该元素在页面上,但是我的测试仍然失败...。
noz.assert_equal(get_conformation_message.text, "Incorrect Credentials") nose.proxy.AssertionError: '' != 'Incorrect Credentials'
+凭证不正确
这是渲染的HTML ...
<div ng-repeat="toaster in toasters" class="toast ng-scope toast-error" ng-class="toaster.type"
ng-click="click(toaster)" ng-mouseover="stopTimer(toaster)" ng-mouseout="restartTimer(toaster)" style="">
<button class="toast-close-button" ng-show="config.closeButton">×</button>
<div ng-class="config.title" class="ng-binding toast-title">Incorrect Credentials</div>
<div ng-class="config.message" ng-switch="" on="toaster.bodyOutputType" class="toast-message">
<!-- ngSwitchWhen: trustedHtml --><!-- ngSwitchWhen: template --><!-- ngSwitchDefault: -->
<div ng-switch-default="" class="ng-binding ng-scope">Incorrect Email/Password</div>
</div>
</div>
我如何才能在Selenium中使用它?
您可以使用显式等待(在我的情况下,每次都可以使用):
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="toast-container"]/div/div[1][@class="ng-binding toast-title"]'))
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句