0

I have an Xpath like this that is changing every time I open the url

//*[@id="awsui-select-23"]/div/awsui-icon/span

What changes is the number after select as for the example:

//*[@id="awsui-select-41"]/div/awsui-icon/span

I tried to give the following xpath but it's not working

("//*[contains(@id, 'awsui-select-')]")

Can you help me understand how should I create/change the Xpath in my code so I can access the element each time the url is opening?

1 Answer 1

1

See this is the xpath

//*[@id="awsui-select-23"]/div/awsui-icon/span

you are using, and digits are changing, so you can use contaons

//*[contains(@id,'awsui-select-')]/div/awsui-icon/span

or (if you want to select the first span)

(//*[contains(@id,'awsui-select')]/descendant::span)[1]

use it like this :

ele = driver.find_element_by_xpath("//*[contains(@id,'awsui-select-')]/div/awsui-icon/span")

Update 1 :

The below works for OP :-

(//*[contains(@id,'awsui-select')]/descendant::span)[2]

or

(//*contains(@id,'awsui-select-')]/div/awsui-icon/span)[2]
Sign up to request clarification or add additional context in comments.

3 Comments

thank you, unfortunately this is the second element on the page with same xpath(similar xpath) it's a trigger icon and it is not working this way :(
Okay could you try this for second button (//*[contains(@id,'awsui-select')]/descendant::span)[2]
Or probably this ,(//*contains(@id,'awsui-select-')]/div/awsui-icon/span)[2]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.