我尝试结合检查两种情况:
I try to combine check for two scenarios:
如果启动检查失败,我们会得到一个重试按钮:
If startupcheck fails we get a try again button:
el = WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((By.NAME, "Try again")))
或者 startupcheck 成功我们在一个自定义对象中得到一个 pin 输入请求:
Or startupcheck succeed we get a pin enter request in a custom object:
el = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//Custom/Edit")))
如何将其合并为一项检查而不必同时检查两者:我尝试了以下方法:
How can this be combined into one check without having to check for both: I tried the following:
check = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(
(By.XPATH, "//Custom/Edit") or (By.NAME, "Try again")
))
但只检查第一个 or 语句.
But only the first or statement is checked.
您可以通过 lambda 表达式使用 OR 子句对两个元素进行组合检查,如下所示:
You can club up combine check for both the elements using OR clause through a lambda expression as follows:
el = WebDriverWait(driver, 20).until(lambda x: (x.find_element_by_name("Try again"), x.find_element_by_xpath("//Custom/Edit")))
另一种解决方案是:
el = WebDriverWait(driver,20).until(lambda driver: driver.find_element(By.NAME,"Try again") and driver.find_element(By.XPATH,"//Custom/Edit"))
作为替代方案,您可以使用等效的 css-selectors 如下:
el = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='Try again'], Custom>Edit")))
这篇关于selenium 两个 xpath 测试合二为一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在python中的感兴趣区域周围绘制一个矩形How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
如何使用 OpenCV 检测和跟踪人员?How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
如何在图像的多个矩形边界框中应用阈值?How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
如何下载 Coco Dataset 的特定部分?How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
根据文本方向检测图像方向角度Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
使用 Opencv 检测图像中矩形的中心和角度Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)