Home > Software engineering >  Why is my element not clicking in selenium after defining xpath?
Why is my element not clicking in selenium after defining xpath?

Time:04-22

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.

Element 1:

enter image description here

Element code: <b 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 id="anonymous_element_1"><b 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.

CodePudding user response:

Try:

click_button=driver.find_element_by_xpath('//*[@id="handler2"]').click()
  • Related