2

I am trying to pass values like First name,Last Name etc in a window popup. I am attaching the screenshot of the page. The Html code behind the page:

<input type="text" name="lastname" value="" onblur="capAll(this);" class="critfont" size="22" maxlength="16">

I tried inspecting it and copy the Xpath, but it is unable to find the Element and is throwing exception.

My C# code is:

var wa = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
var LN = wa.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='pageBodyNoHeader']/form/table[2]/tbody/tr[1]/td[2]/input")));
LN.Click();
LN.SendKeys("Aerere")

When I am running this code, it is throwing me an exception that it has timed out after 10 secs.

I have also tried this code:

Thread.Sleep(1000);
Driver.Instance.FindElement(By.XPath("//*[@id='pageBodyNoHeader']/form/table[2]/tbody/tr[1]/td[2]/input")).Click();
Driver.Instance.FindElement(By.XPath("//*[@id='pageBodyNoHeader']/form/table[2]/tbody/tr[1]/td[2]/input")).SendKeys("Whatever");

Over here the exception that it throws is "It is unable to find the field name".

Can someone please help? Thank youenter image description here

In order to switch to the window popup, I have used the following code:

Driver.Instance.SwitchTo().Window(Driver.Instance.WindowHandles.Last());
Driver.Instance.Manage().Window.Maximize();

1 Answers1

0

I think there may be problem in your xpath, you should try using By.Name as below :-

var wa = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
var LN = wa.Until(ExpectedConditions.ElementExists(By.Name("lastname")));
LN.Click();
LN.SendKeys("Aerere");

Note :- Make sure this element is not inside any frame or iframe. If it is inside then you need to switch that frame or iframe before finding element as :- Driver.Instance.SwitchTo().Frame("frame name or id");

Hope it helps...:)

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • 1
    Hey Saurabh, thanks for the answer..this is actually a very new thing for me and I am the only one in the project..you are just saving my sanity again and again..:) –  Jul 28 '16 at 18:38
  • Currently I am facing another issue, can you please have a look at it.This is the link: http://stackoverflow.com/questions/38642940/handling-colors-in-a-window-popup-using-selenium-c-sharp –  Jul 28 '16 at 18:52