0

Here is my html of my element which i am able to find

<span data-bind="text: myAge()" xpath="1">Showing 1 of 25 people</span>

i could find above element using code like

 [FindsBy(How = How.XPath, Using = "//*[@data-bind='text: myAge()']")]

I have another element in Html like which get dynamic ids

<input class="form-control" data-bind="textInput: code, attr: { id: 'myTable_code_' + $index() }" type="text" id="myTable_code_0" >

i tried to find same as above

 [FindsBy(How = How.XPath, Using = "//*[@data-bind='textInput: code']")]

But i get error that "It is not able to find element"

How to fix this?

1 Answer 1

2

The data-bind attribute is "textInput: code, attr: { id: 'myTable_code_' + $index() }", you need to use all of it

[FindsBy(How = How.XPath, Using = "//*[@data-bind='textInput: code, attr: { id: 'myTable_code_' + $index() }']")]

Or partial attribute

[FindsBy(How = How.XPath, Using = "//*[contains(@data-bind, 'textInput: code')]")]
Sign up to request clarification or add additional context in comments.

6 Comments

Perfect answer. Can you give me some helpful link to learn this?
@James which part are you referring to? I don't know any official docs for anything in my answer, this is just from experience.
The one you used to find using contains
@James I just searched in google, something like "selenium find element by partial attribute", for example stackoverflow.com/questions/31248804/…
There are some good docs on MDN. I prefer CSS selectors and you can find docs on the w3c site.
|

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.