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'.

3 answers

  • answered 2019-10-15 14:03 Dimitar Veljanovski

    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

  • answered 2019-10-15 14:16 Jack Fleeting

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

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

  • answered 2019-10-15 15:15 JOberloh

    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.