2

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

NeverSleeps
  • 1,439
  • 1
  • 11
  • 39

3 Answers3

2

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

//div/button[@title = ('Параметры приложения', 'Application options')]//bdi/text()
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
  • alas( `SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div/button[@title = ('Параметры приложения', 'Application options')]//bdi/text()' is not a valid XPath expression.` – NeverSleeps Oct 15 '19 at 15:10
  • 1
    @NeverSleeps Try it by changing the predicate to `[@title = 'Параметры приложения' or @title= 'Application options']` . – Jack Fleeting Oct 15 '19 at 17:18
0

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

Dimitar
  • 1,148
  • 8
  • 29
  • Yes, I use selenium, but I can't determine the xPath for 'RGF Administrator'. xpath = "//*[@title='Параметры приложения' or @title='Application options']" won't work, At the same time, html may contain other elements with title = 'Application options'. – NeverSleeps Oct 15 '19 at 14:17
0

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.

JOberloh
  • 1,026
  • 2
  • 11
  • 20