显示对象的属性

时间:2014-10-10 12:47:56

标签: selenium-webdriver

在StackOverFlow的登录页面上,单击"使用Stack Exchange登录"链接使"忘记了密码"链接不可见,因此Display属性从块更改为无

忘记了密码

更改为

忘记了密码

如何使用getAttributes()方法验证这一点。

  • 感谢

1 个答案:

答案 0 :(得分:0)

您最好使用wait for Expected Conditions,例如使用python

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

driver = webdriver.Chrome()
driver.get("https://stackoverflow.com/users/login")

#Find and click button
stack_exchange_button = driver.find_element_by_xpath("//span[text()='Log in using Stack Exchange']")
stack_exchange_button.click()

#Let's wait up to 10 seconds for forgot link to be invisible
WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "a[id='forgot-password']")))

print "Link is invisible"

好吧,如果您仍然不想使用等待预期条件,您可以检查以下元素是否存在://a[@id='forgot-password'][contains(@style,'display: none')]