第3步:
这就是我们如何利用这个功能:
if not is_visible(username_xpath): raise RuntimeError("Something went wrong with the username field :(")
username_field = chrome.find_element_by_xpath(username_xpath)
username_field.send_keys(username)
if not is_visible(password_xpath): raise RuntimeError("Something went wrong with the password field :(")
password_field = chrome.find_element_by_xpath(password_xpath)
password_field.send_keys(password)
if not is_visible(sign_in_xpath): raise RuntimeError("Something went wrong with the sign in field :(")
sign_in_btn = chrome.find_element_by_xpath(sign_in_xpath)
sign_in_btn.click()
这里我们调用is_visible函数并分别传递username,password和sign_in按钮的xpath,并等待元素出现超时(这里是30s)。如果不可见,那么我们使用适当的消息引发RuntimeError。
如果它出现在30s之前的任何时间它继续并通过xpath找到元素(现在它在网页上可见,因此这个调用不会引发异常错误)。








暂无数据