0

I have a .NET WebForm and I need to click a link using Selenium and can't use the text content (because of translation issues). How can I identify this element?

<a href="javascript:__doPostBack('ctl01','')">registration form</a>

I have tried the following, which does not work:

var element = Driver.FindElementsByXPath($"//*[@href='ctl01']");
1
  • 2
    Update the question with some more of the outerHTML. Commented Apr 3, 2018 at 11:42

3 Answers 3

1

The problem is that you are trying to look for an id within the xpath, while the element does not contain an id.

In this case, this should work:

var element = Driver.FindElementsByXPath($"//a[contains(text(), 'registration form')]");

This will only work if all the elements which you are trying to find are links with the text registration form in it.

If you want to find elements on the href, use:

var element = Driver.FindElementsByXPath
("//a[contains(@href, 'javascript:__doPostBack('ctl01','')')]");
Sign up to request clarification or add additional context in comments.

3 Comments

You're right - edited to show my actual code includes href, not id. D'oh!
Ultimately, this answer was the closest. I have posted my final solution.
Good to see you got through it and glad I could help :-)
1

Ultimately decided to identify within the href attribute by partial string:

.FindElementsByXPath($"//*[contains(@href, '{id}')]")

This is because putting the whole value of the javascript text into the Selenium call caused it to fail parsing.

Comments

0

try searching for the a href instead of the id like this: a[@href='javascript:__doPostBack('ctl01','')'] with FindElementsByXPath then on the var element try using SendKeys like so:

element.SendKeys(Keys.Enter); 

Comments

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.