如何在 selenium python 中使用 div 中的 id 和 class 查找元素,然后单击它:
<div id="abc" class="xyz" style="" role="presentation"></div>
我正在使用以下代码:
arrow = driver.find_element_by_xpath('//div[@id="abc"][@class="xyz"]')
arrow.click()
但是我得到的错误是:
NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//div[@id=\"abc\"][@class=\"xyz\"]"}
最佳答案
在下面使用:-
arrow = driver.find_element_by_xpath('//div[@id="abc" and @class="xyz"]')
arrow.click()
此处在 XPath 中,"and" 运算符用于将 id 和 class 组合在一起
希望对你有帮助:)
关于python - 如何使用 div 中的 id 和 class 在 selenium python 中查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615472/