NeverSleeps
NeverSleeps

Reputation: 1902

How to search title in HTML using XPath?

I am trying to get 'RGF Administrator' text from the html example below. The difficulty is that title can take two values: 'Application Settings' or 'Параметры приложения'. At the same time, html may contain other elements with title = 'Application options'.

Which can i use xPath for it?

<div>
    <button
    title="Application options">
        <span>
            <span>
                <bdi>
                    RGF Administrator
                </bdi>
            </span>
        </span>
    </button>
</div>

I use selenium, but I can't determine the xPath for 'RGF Administrator'.

xpath = "//*[@title='Параметры приложения' or @title='Application options']"

won't work since at the same time, html may contain other elements with title = 'Application options'.

Upvotes: 2

Views: 3143

Answers (3)

JOberloh
JOberloh

Reputation: 1106

How many bdi containers do you have on the webpage? If there is only 1, you can literally just use

//bdi

And you don't need any pathing.

Upvotes: 0

Jack Fleeting
Jack Fleeting

Reputation: 24930

Try this xpath expression on your actual xml and see if it works:

//div/button[@title = ('Параметры приложения', 'Application options')]//bdi/text()

Upvotes: 2

Dimitar
Dimitar

Reputation: 1180

If you are using selenium, then you need to use the get_attribute(string) method. So for example, when you find the elements xpath:

element = driver.find_element_by_xpath("xpath")

and then do

element.get_attribute("title")

to get Application options

Upvotes: 0

Related Questions