0

I have probably spent a good 8 hours trying to figure this out but am constantly failing. I have searched an age for a solution

I am trying to find an selenium element by partial id match using xpath (c# selenium libraries). The following works perfectly fine. The partial text is sel_1-rowse1

IWebElement elem = wait5.Until(x => x.FindElement(By.XPath("//a[contains(@id,'sel_1-rowsel')]")));   

However when I want to use a variable named partial this does not work

string partial = "sel_1-rowse1";
IWebElement search = wait.Until(x => x.FindElement(By.XPath(String.Format("//a[contains(@id,'{0}')]", partial))));

or

IWebElement search = wait.Until(x => x.FindElement(By.XPath(String.Format("//a[contains(@id,{0})]", partial))));

I have tried single quotes double quotes and escape chars. But cant figure this out. I cant even provide the error as its picking up a valid id. Brain is severely depleted on this one.

2
  • "does not work?" How? What's the output from your two examples above? Commented Apr 20, 2015 at 10:14
  • Sorry my debugging was fairly difficult as I could not debug on the network I ran the program on, Constant use of Console.Writeline to see what was happening in the program. The next two replies resoved the issue. Commented Apr 22, 2015 at 22:05

2 Answers 2

3

Just an observation, the first example element id ends with lower case 'L' (so l) while the second one with number 1. Might be just a copy paste error but worth asking...

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This was the problem. It took this long to not notice the difference between 1 and l . Always stuns me how many hours I can spend on something so trivial.
1

partial is a reserved keyword in C#.

Refactor partial to something else (not reserved by C#) and you should be golden.

1 Comment

Brilliant. This did not resolve the issue alone but I did remove partial

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.