WebDriverWait中的逻辑运算符预期条件 [英] Logic Operators in WebDriverWait Expected Conditions

查看:177
本文介绍了WebDriverWait中的逻辑运算符预期条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python/Selenium提交表单,然后让Web驱动程序通过使用类ID的预期条件来等待下一页的加载.

I'm using Python / Selenium to submit a form then I have the web driver waiting for the next page to load by using an expected condition using class id.

我的问题是可以显示两个页面,但是它们没有共享不在原始页面中的唯一元素(我可以找到).一页的唯一类为mobile_txt_holder,另一页可能的类ID为notfoundcopy. 我想使用等待方式来查找mobile_txt_holdernotfoundcopy出现.

My problem is that there are two pages that can be displayed but they do not share an unique element (that I can find) that is not in the original page. One page has a unique class is of mobile_txt_holder and the other possible page has a class id of notfoundcopy. I would like to use a wait that is looking for mobile_txt_holder OR notfoundcopy to appear.

是否可以将两个预期条件合并为一个等待?

Is it possible to combine two expected conditions into one wait?

关于我要寻找的基本想法,但显然行不通:

Basic idea of what I am looking for but obviously won't work:

WebDriverWait(driver, 30).until(EC.presence_of_element_located(
    (By.CLASS_NAME, "mobile_txt_holder")))
    or .until(EC.presence_of_element_located((By.CLASS_NAME, "notfoundcopy")))

我真的只需要编程以等待下一页加载,以便我可以解析源代码.

I really just need to program to wait until the next page loads so that I can parse the source.

示例HTML:

<p class="notfoundcopy">Unfortunately, the number you entered is not in our tracking system.</p>

推荐答案

除了通过or子句组合2个expected_conditions之外,我们还可以轻松构造一个CSS来满足我们的要求以下CSS将在mobile_txt_holder类或notfoundcopy类中寻找EC:

Apart from clubbing up 2 expected_conditions through or clause, we can easily construct a CSS to take care of our requirement The following CSS will look either for the EC either in mobile_txt_holder class or in notfoundcopy class:

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, ".mobile_txt_holder, .notfoundcopy"))

您可以在硒两个xpath测试中找到详细的讨论

这篇关于WebDriverWait中的逻辑运算符预期条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆