My code:
driver.find_element_by_xpath("//svg[@class='SvgIcon_root__keb_Y'][@aria-label='Вернуться к старому дизайну']").click()
My error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//svg[@class='SvgIcon_root__keb_Y'][@aria-label='Вернуться к старому дизайну']"}
What am I doing wrong? Why doesn't Selenium find him? Because of focusable="false" and aria-hidden="true"? If because of this, how do I identify this element and click on it?
To access the the SVG
element,the xpath
should be different. It should be like.
//*[local-name()='svg' and @aria-label='Вернуться к старому дизайну']
Or
//*[local-name()='svg' and @class='SvgIcon_root__keb_Y']
Or
//*[name()='svg' and @aria-label='Вернуться к старому дизайну']
Ideally your code should be like
driver.find_element_by_xpath("//*[local-name()='svg' and @aria-label='Вернуться к старому дизайну']").click()
You can find following reference, how to interact with svg
element xpathforsvgelement
I can't tell based on your cropped screenshot, but this element may be in an Iframe. If it's the case, you need to switch your WebDriver's view to this frame.
iframe = driver.find_element_by_xpath("Put the Iframe Xpath here")
driver.switch_to.frame(iframe)
Then you can get the element you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.