0

The test finds the element because it doesnt fail but its unable to send the parameters.

Tried following :

driver.FindElement(By.XPath("//input[@type='search']")).Clear();
driver.FindElement(By.XPath("//input[@type='search']")).Click();

IWebElement wb = driver.FindElement(By.XPath("//input[@type='search']"));
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("arguments[0].value='QA Test Automation Developer';", wb);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

As it is a <input> tag you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']")));
    wb.Click();
    wb.Clear();
    wb.SendKeys("QA Test Automation Developer");
    
  • XPath:

    IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@type='search']")));
    wb.Click();
    wb.Clear();
    wb.SendKeys("QA Test Automation Developer");
    

Using IJavaScriptExecutor

  • Using setAttribute() and innerHTML:

    IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']")));
    IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
    jse.ExecuteScript("arguments[0].setAttribute('innerHTML','QA Test Automation Developer')", wb);
    
  • Using setAttribute() and textContext:

    IWebElement wb = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[type='search']")));
    IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
    jse.ExecuteScript("arguments[0].setAttribute('textContext','QA Test Automation Developer')", wb);
    

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Tried all the above options but still does not work. This is the link I am trying to automate if you can check it out(https://jobs.labcorp.com/).There will be a keyword search and submit that does not seem to find the element. – AutomationUserNC Sep 21 '20 at 14:46