1

Sendkeys is entering the value for below search dropdown only in debug mode.It doesn't work in full run even after adding waits or clicking and entering the value. Using Javascript, I'm able to enter the value in full run but search results are not shown which is not allowing me to select the value from the list of search results. HTML code: code image

Code for sendkeys used: driver.FindElement(FirstDestination).SendKeys("italy");

Code for javascript used:

IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("arguments[0].value='italy';", driver.FindElement(FirstDestination));

Tried to use Actions class as well but no luck. Any quick help with this issue is really appreciated. I'm using Selenium with C# and specflow on Windows 10

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Divya
  • 15
  • 2
  • so if Js commands work fine and you don't see any result, maybe you are missing a step in your script for e.g: clicking on the search bar, or hitting the enter button. – cruisepandey Apr 10 '22 at 07:24
  • Also, if that is the case, we'd need a link to the page to reproduce the same issue at our end. – cruisepandey Apr 10 '22 at 07:25
  • after entering the value using javascript, I have used sendkeys to press enter but sendkeys is deleting the value in the field.Is there any way we can tab out using js as sendkeys is not working in my case. Unfortunately i cannot share the link but the field is similar to google search box – Divya Apr 10 '22 at 07:57

1 Answers1

0

You can use WebDriverWait to send the keys like below:

IWebElement firstDestination = wait.Until(e => e.FindElement(By.Id("Travel-TripDetails-DestinationFlexdata--label")));
firstDestination.SendKeys("Italy");

there's no need to use IJavaScriptExecutor as WebDriverWait would suffice in this case.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38