简体   繁体   中英

xPath select Svg parent of node

I have this html code :

<button>
    <svg aria-label="Options">
        <circle></circle>
    </svg>
</button>

I need to select the button to click it like this :

browser.find_element_by_xpath('//svg[@aria-label="Options"]/parent::button').click()

I've also tried this :

browser.find_element_by_xpath('..//button/svg[@aria-label="Options"]').click()

But it says :

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"..."}

How to select this button please ? I cannot show the all code, the button is not reachable easily because it has random classes... Thanks !

Here is the xpath that you can use.

//*[@aria-label='Options'][name()='svg']/parent::button

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM