Alexander Vedmed'
Alexander Vedmed'

Reputation: 184

how to select element in selenium by custom identifier

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?

Upvotes: 1

Views: 592

Answers (1)

Satish Michael
Satish Michael

Reputation: 2015

You can use the CSS selector.

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

Upvotes: 4

Related Questions