热线电话:13121318867

登录
2019-04-15 阅读量: 562
如何使用Python进行非阻塞等待(3)

第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找到元素(现在它在网页上可见,因此这个调用不会引发异常错误)。

0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子