Lo1*_*988 9 python selenium xpath
我想分别点击或更多,展开“随时”按钮。我试图通过 class_name 和 xpath 定位元素。问题是所有三个“选项”的类和 xpath 都是相同的。因此,我想使用 aria-label 选择并单击或扩展该元素。我找到了一些建议,但对我不起作用。最重要的是,我尝试在 python 3 中做到这一点。我也尝试过:
driver.find_element_by_xpath(""" //div*[@aria-label='Any Time'] """).click()
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
有人可以帮我吗?提前谢谢了!
driver.find_element_by_xpath(""" //div*[@aria-label='Any Time'] """).click()
Run Code Online (Sandbox Code Playgroud)
Deb*_*anB 14
使用该aria-label属性,您可以尝试以下操作xpath:
driver.find_element_by_xpath("//div[@aria-label='Any time']/div[@class='mn-hd-txt' and text()='Any time']");
Run Code Online (Sandbox Code Playgroud)
或者
driver.find_element_by_xpath("//div[@aria-label='Any time']/div[@class='mn-hd-txt'][text()='Any time']");
Run Code Online (Sandbox Code Playgroud)
如果使用aria-label属性不是强制性要求,您可以使用以下内容:
driver.find_element_by_xpath("//div[@class='hdtb-mn-hd']/div[@class='mn-hd-txt' and text()='Any time']");
Run Code Online (Sandbox Code Playgroud)
或者
driver.find_element_by_xpath("//div[@class='hdtb-mn-hd']/div[@class='mn-hd-txt'][text()='Any time']");
Run Code Online (Sandbox Code Playgroud)
Bra*_*bey 10
所以,过去几天我一直在努力解决这个问题,事实证明这是一个巨大的头痛。aria-label 基本上是唯一可靠的属性,而 xpath 解决方案对我不起作用。
一时兴起,我尝试使用:
driver.find_elements_by_css_selector("[aria-label=XXXX]")
Run Code Online (Sandbox Code Playgroud)
其中 XXXX 是我正在寻找的咏叹调标签。像魅力一样工作。
说了这么多,请尝试使用 css 选择器。它只是有效。
| 归档时间: |
|
| 查看次数: |
41992 次 |
| 最近记录: |