xBamboochax xBamboochax - 4 months ago 12
jQuery Question

Find element by part of id-selenium web driver

Hi guys I have element which has these atr :

<input type="text" class="id-element clearable ui-input-text ui-body-a" data-mini="true" maxlength="50" id="bec563ae2-AccountUser_Name">


And I want it find by
ID
, but the part of
id=bec563ae2-
is automatic generated for every single user.
Then using will don´t work:

IWebElement profilUser = driverGC.FindElement(By.Id("id"));


Yep there is still way to find it by
ClassName
(but it doesn´t work correctly here) or by
CssSelector
, but if I try to find it by
CssSelector
, I will get into some part of this element, but I will not be able to work with it(filling name).

Ok I tried this one, but unsuccessfully :

IWebElement profilUserName = driverGC.FindElement(By.CssSelector(".ui-page-active .msls-dialog-inner-frame .msls-tab-content .msls-first-row .msls-presenter-content .div:nth-child(1)"));
profilUserName.SendKeys("Paul");

Answer

Seems like you are looking for an element with an ID that ends with a specific string: Here is how to do it using css selector

driverGC.FindElement(By.CssSelector("input[id$='AccountUser_Name']"));
Comments