目前的情况是:
send_keys
到字段get_attribute("value")
我的代码:
def fill_twitter(self):
enter_twitter = "http://" + fake.text(max_nb_chars=13) + ".com"
twitter_field = self.find_element(*ContractorsLocators.TWITTER)
twitter_field.send_keys(enter_twitter)
self.find_element(*ContractorsLocators.SAVE_BUTTON).click()
time.sleep(4)
assert twitter_field.get_attribute("value") == enter_twitter
我的错误:
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
如何获得get_attribute("value")
?你知道吗
当页面被刷新时,最好在元素得到
Stale.
之前保存属性的值要在页面刷新后检查元素是否可见,请使用显式sleep()函数,并在4秒钟后使用
WebDriverWait
检查组件是否可见。你知道吗访问http://selenium-python.readthedocs.io/waits.html#explicit-waits以获得更好的理解。你知道吗
这个页面的most frequent cause是元素所在的页面已经刷新,或者用户已经导航到另一个页面。你知道吗
正如您所说的,当单击save按钮时,页面将被刷新。因此,为了避免这种情况,您需要再次找到相同的元素(refresh element)来获得它们的值,如下所示:
相关问题 更多 >
编程相关推荐