我正在运行一个测试用例,其中一部分是检查iframe中的元素是否可见。我执行了以下操作,但它不起作用,总是转到except块。谢谢
try:
time.sleep(2)
driver.switch_to.frame("iframe-xxxxxxxxxxxxxxxxxx")
time.sleep(2)
if driver.find_element_by_xpath("//div[@class='col-11 answer-feedback-label']//div[contains(text(),'Hello World!')]"):
logging.info("Success")
except:
logging.error("Failure")发布于 2019-12-24 15:27:28
要检查<iframe>中的元素是否可见,就像<iframe>中的所需元素一样,因此您必须:
适用于visibility_of_element_located().
frame_to_be_available_and_switch_to_it().
- Code Block:从selenium导入webdriver从selenium.webdriver.support.ui导入WebDriverWait从selenium.webdriver.support导入expected_conditions作为EC从selenium.webdriver.common.by导入通过导入org.openqa.selenium.TimeoutException;。。。try: driver(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,“iframe_XPATH”)) WebDriverWait(driver,div "//div@class='col-11 answer-feedback-label‘//WebDriverWait(text(),'Hello World!’)“)除TimeoutEception以外的logging.info(“成功”):logging.error(“失败”)
上找到相关讨论
https://stackoverflow.com/questions/59464661
复制相似问题