Home > Enterprise >  Click on SVG image selenium python
Click on SVG image selenium python

Time:12-25

I am trying to use selenium for clicking on a svg element in order to close a pop up:

<div >
<svg name="ClosePopUp"  width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"><path d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z" fill="#ffffff"></path></svg>>

Following previous answers on stack overflow, I have tried:

wd.find_element_by_xpath('//div[@]/*[name()="svg"][@id="Root"]').click()

and

wd.find_element_by_xpath('//div[@]/*[name()="svg"][@name="ClosePopUp"]').click()

But in both cases, I have got the same error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@]/*[name()="svg"][@id="Root"]"}

How could I close the emergent pop up with selenium python on this page: https://data.anbima.com.br/debentures/JTEE11/caracteristicas

CodePudding user response:

You can try the below locator:

wd.find_element(By.XPATH, ".//div[@class=' light-ui-pop-up--header']/*[local-name()='svg']").click()
  • Related