如何在selenium webdriver中以不区分大小写的方式查找包含特定单词的链接

Bry*_*res 4 python selenium selenium-webdriver

我希望能够找到包含以下内容的链接:hello,Hello,hEllo,heLlo等.到目前为止,我使用的find_elements_by_partial_link_text是casse敏感:

links = driver.find_elements_by_partial_link_text('hello')
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 7

find_elements_by_partial_link_text()并且find_elements_by_link_text()都是区分大小写的,并且行为不容易改变.

相反,通过xpath和apply lower-case()函数查找链接:

links = driver.find_elements_by_xpath('//a[contains(lower-case(.), "hello")]')
Run Code Online (Sandbox Code Playgroud)

另见: