CS agents will respond to tickets via forum instead of private helpdesk to support other users with similar issues.

select single web element using xpath

From console I get all elements like $x('//span[text()="blablabla"]') And I get result like (3) [span, span, span] And I can get second element using [1] like $x('//span[text()="blablabla"]')[1]
But gets error when I create test object like //span[text()="blablabla"][1] It works with //span[text()="blablabla"]

Tagged:

Comments

  • Hi there,

    What error message from your side?

  • @Vinh Nguyen so if I use xpath //span[text()="blablabla"]it should return array or list of web elements? since it matches more that 1. And I want to select specific element from array or list. Generally you can do like //span[text()="blablabla"][1] which will return element at index 1 from array of web elements.
    But here is doesn't seem to return single element.

    Finding web element with id: 'Object Repository/test/test_object' located by 'By.xpath: //span[text()="blablabla"][1]' in '5' second(s)
    09-20-2017 09:01:57 AM - [INFO]   - **Found 3 web elements** with id: 'Object Repository/test/test_object' located by 'By.xpath: //span[text()="blablabla"][1]' in '5' second

    As you see it finds 3 elements, how can I select only one from these 3 elements?
    Then I can use each element to verify different asserts, that's the end goal.
Sign In or Register to comment.