i tried using xpath, Id to find elements. even though im getting the error "unable to locate the element" please can anyone help?

HTML Snippet

<input type="text" value="" maxlength="256" id="FileLeafRef_8553196d-ec8d-4564-9861-3dbe931050c8_$onetidIOFile" title="Name Required Field" class="ms-long" size="35">

C# Code

  • yes can you share the relevant HTML?
    – Paras
    Jul 21, 2016 at 10:45
  • <input type="text" value="" maxlength="256" id="FileLeafRef_8553196d-ec8d-4564-9861-3dbe931050c8_$onetidIOFile" title="Name Required Field" class="ms-long" size="35"> Jul 21, 2016 at 10:50
  • im unable to enter the text in textbox field..... Jul 21, 2016 at 10:55
  • i tried to enter the text in the textbox field, but im getting error "unable to locate element" even after its clicking in text box. Jul 21, 2016 at 11:16
  • can you share your code, how would I suppose to help you, if you don't share the code.
    – Paras
    Jul 21, 2016 at 11:17

5 Answers 5


You can use any of the below mentioned way to select that particular element.

driver.FindElement(By.Xpath("//input[@title='Name Required Field']")).sendKeys("Newprojecttest");



Hope it helps!

  • I didn't see this answer before posting mine, which has nearly the same content. Voting for this answer. Feb 17, 2017 at 23:56

You can try different selectors based on existing value of attributes that do not change or to use a selector based on a fixed part of the attribute.

Here are some css selectors that you can try:

input[title='Name Required Field']

I recommend using a CSS selector, yours would look something like:

var element = driver.FindElement(By.CssSelector("input.ms-long"));

Hope this helps


This is just a guess based on the HTML you provided, but is the ID different each time the page is loaded? This seems likely based on the fact that the ID contains a GUID.

If that's the case, my recommendation would be to use XPath as follows:


This will locate the first element on the page whose ID contains "FileLeafRef", so even if the GUID is unique each time the page is loaded, the target element will be found.

Note that if there are multiple text inputs that have similar IDs, you will have to get more specific.

Alternatively, if the @title attribute is unique among elements on the page, you could use that as well since it is nice and clean:

driver.FindElement(By.XPath("//input[@title='Name Required Field']")).SendKeys("Newprojecttest");

in some times you will face this type of problems to find the elements, at that time you can try different methods, mostly it will work for


By.name will work most of the times, same i have faced and resolved with these name locator.

  • but in the code i commented ..there is no name in that.so i can do that by.name? Jul 21, 2016 at 11:14
  • In Case for element name is mention then you can use for that.like below.<input id="userNameId" class="loginfield" type="text" value="" name="userLogin.userId"/>
    – Rajesh k
    Jul 21, 2016 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.