opts_to_select = [o for o in opts if o.text.startswith('W33')]
my_option = opts_to_select[0] # select first match
# (Maybe you also want to raise an error if
# there is more than one match.)
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
您可以在
Select
对象上获得具有options
属性的所有选项的列表:然后,检查哪一个匹配。在您的示例中,检查
text
属性:然后选择它:
资料来源:^{} at selenium-python documentation
由于可见文本的静态部分(即} 可能无效。你可能不得不考虑其中之一:
W33
)后面总是跟着一个变量文本,例如(only 4 left)
、(only 3 left)
等,因此^{另类
作为替代方案,您也可以使用基于xpath的Locator Strategy,如下所示:
理想情况下,您需要为
element_to_be_clickable()
诱导WebDriverWait,如下所示:注意:您必须添加以下导入:
参考文献
您可以在以下内容中找到相关讨论:
相关问题 更多 >
编程相关推荐