python/ selenium/ xpath/ webdriver

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='Вернуться к старому дизайну']"}

HTML code

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.

Related Question XPath is correct but doesn't find the web element Selenium doesn't recognize element by XPath Python Selenium find element XPath doesn't work Python 3 + Selenium: Find element by Xpath and text() doesn't work Selenium XPath “[@value]” Doesn't Match Element With Value Why doesn’t Selenium find an element with this XPath expression? Python Selenium find element by xpath and click doesn't seem to work robotframework doesn't see the xpath Copy xpath Doesn't Provide Correct xpath? Selenium Python - Can't Find Correct CSS or Xpath in deeply nested HTML Element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM