【发布时间】:2017-06-09 22:12:27
【问题描述】:
我进行了很多搜索,但似乎无法让 Selenium 等待 id 不具有特定值。我尝试过的一些事情:
超时:
wait.until(EC.text_to_be_present_in_element_value((By.ID, "price"), not " $0.00"))
这会抛出TypeError: 'bool' object is not callable:
wait.until(not EC.text_to_be_present_in_element_value((By.ID, "price"), " $0.00"))
这会抛出TypeError: coercing to Unicode: need string or buffer, bool found:
wait.until(EC.text_to_be_present_in_element((By.ID, "price"), not " $0.00"))
注意:
这是价格 ID 中的唯一值
wait = WebDriverWait(browser, 10)
奖励答案:
整个问题是价格从“0.00 美元”开始,然后变为显示加载 gif 的多个元素。最后,它将显示实际价格。为了完成我的任务,我使用下面接受的答案 (until_not) 来检查 0 是否已成为 gif,并使用自定义函数来检查正则表达式是否与“$0”匹配。我使用了来自here 的函数,其正则表达式模式为“\$(?!0)\w”。
【问题讨论】:
标签: python python-2.7 selenium web-scraping