我的应用程序中有一个链接,该链接在60秒后启用。我必须验证,该链接仅在60秒后才能在此之前启用。已经尝试了以下方式:
-
我尝试使用fluent wait/webdriver wait/thread.sleep进行
element to be clickable()
,所有这些都在返回该元素,而该元素实际上是禁用到60秒的地方。 -
我也尝试过getAttribute("禁用"(,它也返回false。
我在HTML中看到的唯一区别是类属性。禁用时,类属性值在其上添加了其他文本(禁用(。
尝试一下(需要根据需要进行Tweek(:
long ts1 = System.currentTimeMillis()/1000;
new WebDriverWait(driver, 60).until(ExpectedConditions.attributeToBe(element, "disabled", null);
long ts2 = System.currentTimeMillis()/1000;
Assert.assertTrue((ts2-ts1)>=60);
如果该元素在60秒开始之前没有禁用,则断言将失败。
随着应用程序中的链接在 60 秒之后启用,直到那时(被禁用( class
属性包含附加值禁用,要验证此用语酶,您可以使用try-catch{}
块,并且可以使用以下任何一个基于Python的定位器策略:
-
CSS_SELECTOR
:try: WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "tag_name[some_attribute='value_of_some_attribute']:not(.disabled)"))) print("Class attribute failed to contain the value disabled for 60 seconds") except TimeoutException: print("Class attribute successfully contained the value disabled for 60 seconds")
-
XPATH
:try: WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//tag_name[@some_attribute='value_of_some_attribute' and not(@class='disabled')]"))) print("Class attribute failed to contain the value disabled for 60 seconds") except TimeoutException: print("Class attribute successfully contained the value disabled for 60 seconds")