1

I am trying to automate a web page which has about 50 select buttons and here's an example

<input type="button" value="اختر" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Select$2')">

The part which is 'Select$2' is what changes from a button to another .. How can I specify the xpath of such a button? I could select all the buttons using this

//input[@type='button']

But I would like to select specific button.

1 Answer 1

1

If you want to use unique part of onclick attribute as locator try

//input[@type='button' and contains(@onclick, 'Select$2')]
Sign up to request clarification or add additional context in comments.

3 Comments

Amazing. Thanks a lot. How can I avoid selecting 20 and 21 and 22 and so on, as the xpath selects them too?
@YasserKhalil maybe try to add escape characters like contains(@onclick, '\'Select$2\'') to specify that you want onclick attribute to contain exactly string 'Select$2', but not sub-string Select$2... I'm not sure how it should be done in VBA. In Python we can just mix quotes '//input[@type="button" and contains(@onclick, "'Select$2'")]'
Thanks a lot. I could solve that point in VBA like that. Declare a variable Dim sSel As String then assign the value sSel = "'Select$2'" and finally used this line bot.FindElementByXPath("//input[@type='button' and contains(@onclick, " & sSel & ")]").Click

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.