lundi 20 avril 2015

Adding string variable to xpath c# selenium

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.

Aucun commentaire:

Enregistrer un commentaire