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

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

问题描述

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

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

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

我正在寻找但显然行不通的基本想法:

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

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

示例 HTML:

<p class="notfoundcopy">很遗憾,您输入的号码不在我们的跟踪系统中.</p>

解决方案

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

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

<块引用>

您可以在 selenium 两个 xpath 测试合二为一中找到详细讨论

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.

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.

Sample HTML:

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

解决方案

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"))

You can find a detailed discussion in selenium two xpath tests in one

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

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