how to select element in selenium by custom identifier

Viewed 175

I'm trying to use selenium with python for parsing page. I have a HTML page with this markup:

    <body>
        <div my-id="article-3">some text</div>
        <div my-id="article-4">some text1</div>
    </body>

And I need to specify not only the value, but also the name:

    divs = driver.find_element_by_id('article-3')

Because my-id="article-3" is not id="article-3".

How to set custom id?

1 Answers

You can use the CSS selector.

div = driver.find_element_by_css_locator('div[my-id="article-3"]')
Related