如何使用 div 中的 id 和 class 在 selenium python 中查找元素

Ani*_*ket 4 python selenium xpath

如何在 div 中同时使用 id 和 class 在 selenium python 中查找元素,然后单击它:

<div id="abc" class="xyz" style="" role="presentation"></div>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码:

arrow = driver.find_element_by_xpath('//div[@id="abc"][@class="xyz"]')
arrow.click()
Run Code Online (Sandbox Code Playgroud)

但我收到错误如下:

NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//div[@id=\"abc\"][@class=\"xyz\"]"}
Run Code Online (Sandbox Code Playgroud)

Shu*_*ain 9

在下面使用:-

arrow = driver.find_element_by_xpath('//div[@id="abc" and @class="xyz"]')
arrow.click()
Run Code Online (Sandbox Code Playgroud)

希望它会帮助你:)