python - Selenium Python:等待元素的背景颜色为'rgb(...)`
问题描述
使用 Selenium 和 Python,我们如何等待具有 id 的某个元素foo
具有backgroundColor
of "rgb(1, 2, 3)"
?
到目前为止,我认为它应该是这样的
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
expected_backgroundColor = EC.some_method((By.ID, "foo"))
WebDriverWait(self.driver, 15).until(expected_backgroundColor)
但不确定EC
使用哪种方法。
任何建议都会有所帮助!谢谢!
解决方案
您可以为此使用presence_of_element_located
orvisibility_of_element_located
方法。让我们看看下面的例子,
预期元素xPath
:
//input[@id='rgb(1, 2, 3)']
代码:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//input[@id='rgb(1, 2, 3)']')))
或者
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//input[@id='rgb(1, 2, 3)']')))
在 Java 中, 和 方法等attributeToBe
方法attributeContains
可用attributeNotToBeEmpty
,但不确定这些方法在 Python 中是否可用。
Java 示例:
WebElement element = driver.findElement(By.xpath("xPath "));
wait.until(ExpectedConditions.attributeToBe(element, "id", "rgb(1, 2, 3)"));
推荐阅读
- apache-kafka - 获取特定项目的生产和消费时间戳的选项?
- python-3.x - 如何用多个数据框列的值替换列中的值
- python - 仅使用 def 返回文件的平均值
- python - append方法不正确?
- sql - 动态列别名创建和加入
- java - 函数式接口和递归
- javascript - 警告:失败的道具类型:提供给“路线”的无效道具“组件” - react-router-dom
- r - 如何从 tibble 中删除非缺失值与其他行中的值子集匹配的行?
- java - 如何在 java 中为我的 morse cod 编写 junit 测试
- ios - 不兼容的指针类型将“AVCapturePhotoSettings *”发送到“NSArray”类型的参数
* _Nonnull'