等待在 Selenium 中选择元素
Wait for the element to be selected in Selenium
有一个文本字段在特定时间后由网站自动填充,文本光标移动到相同的文本字段
<html>
<div>
<input type=text id=name>Enter here</div>
<html>
几秒钟后,网站会自动选择并填写输入字段。我希望 selenium 等到它被选中,然后继续执行进一步的代码。
我已经完成了:
wait=WebDriverWait(driver,10)
element=driver.find_element_by_id("name")
wait.until(expected_conditions.element_to_be_selected(element))
即使网站填写了文本字段,它也会抛出错误。
expected_conditions.element_to_be_selected()
紧随其后 spec。具体来说:
This operation only makes sense on input elements of the Checkbox- and Radio Button states (emphasis mine)
您输入的是文本类型,因此无法正常工作。
您将不得不使用不同的方法。也许是这样的:
- 阅读文本(
@value
属性)。
- 等到它变成其他任何东西。
其他类似问题的一些答案似乎适用于各自的问题。不过,我没有找到 python 的任何内容。
我所做的是 运行 一个无限循环,直到元素中存在的文本的长度不等于零。
while 1 is not 5:
if len(element.get_attribute("value")) is not 0:
break
else:
continue
value element 的属性具有文本字段中存在的任何字符串的值。
有一个文本字段在特定时间后由网站自动填充,文本光标移动到相同的文本字段
<html>
<div>
<input type=text id=name>Enter here</div>
<html>
几秒钟后,网站会自动选择并填写输入字段。我希望 selenium 等到它被选中,然后继续执行进一步的代码。 我已经完成了:
wait=WebDriverWait(driver,10)
element=driver.find_element_by_id("name")
wait.until(expected_conditions.element_to_be_selected(element))
即使网站填写了文本字段,它也会抛出错误。
expected_conditions.element_to_be_selected()
紧随其后 spec。具体来说:
This operation only makes sense on input elements of the Checkbox- and Radio Button states (emphasis mine)
您输入的是文本类型,因此无法正常工作。
您将不得不使用不同的方法。也许是这样的:
- 阅读文本(
@value
属性)。 - 等到它变成其他任何东西。
其他类似问题的一些答案似乎适用于各自的问题。不过,我没有找到 python 的任何内容。 我所做的是 运行 一个无限循环,直到元素中存在的文本的长度不等于零。
while 1 is not 5:
if len(element.get_attribute("value")) is not 0:
break
else:
continue
value element 的属性具有文本字段中存在的任何字符串的值。