Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my element not clicking in selenium after defining xpath?

I am writing a selenium code to go to a website and click on the following element to expand its drop down list:

Reports

Now this area is comprised of two elements.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Element 1:

enter image description here

Element code: <b class="icon" id="handler2"></b>

Full Xpath: /html/body/div[4]/div/div/div[3]/div[2]/div[2]/ul/li/ul/li/p/b

Element 2:

enter image description here

Element code: <p class="wrap button draggable" id="anonymous_element_1"><b class="icon" id="handler2"></b>Reports</p>

Full Xpath: /html/body/div[4]/div/div/div[3]/div[2]/div[2]/ul/li/ul/li/p

I used element 1. My selenium code is lengthy but the the line i used to click ‘reports’ is:

click_button=driver.find_element_by_xpath('/html/body/div[4]/div/div/div[3]/div[2]/div[2]/ul/li/ul/li/p/b').click()

It doesn’t click the button though. I’m not sure why. Does anyone know how I can solve this problem?. It is worth noting that if you use element 2, then a double click is required.

>Solution :

Try:

click_button=driver.find_element_by_xpath('//*[@id="handler2"]').click()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading