Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find element in selenium python using id and class in div

How to find element in selenium python using both id and class in div and then click it:

<div id="abc" class="xyz" style="" role="presentation"></div>

I am using the following code:

arrow = driver.find_element_by_xpath('//div[@id="abc"][@class="xyz"]')
arrow.click()

But I am getting error as:

NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//div[@id=\"abc\"][@class=\"xyz\"]"}
like image 323
Aniket Avatar asked Dec 19 '22 17:12

Aniket


1 Answers

Use below:-

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

Here in XPath "and" operator is being used to combine id and class together

Hope it will help you :)

like image 96
Shubham Jain Avatar answered Dec 21 '22 11:12

Shubham Jain