0

I'm trying to fill a form with Selenium, but I'm getting Unable to locate element: #PaymentMethod_FullName when the element clearly exists on Developer Tools on firefox. I already tested for iframe, and there's no iframe. Firefox Developer Tools

I'm trying to do:

driver.FindElement(By.Id("PaymentMethod_FullName")).SendKeys(name);

but I already tried with the css selector #PaymentMethod_FullName and the XPath //*[@id='PaymentMethod_FullName'], so I have no idea why it's not working. Also, this error is present for all the inputs on that form. Thanks in advance.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

The desired element is an dynamic element so you have to induce WebDriverWait for the desired ElementToBeClickable and you can use either of the following Locator Strategies:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.tooltip#PaymentMethod_FullName"))).SendKeys(name);
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='tooltip' and @id='PaymentMethod_FullName']"))).SendKeys(name);
    

You can find a detailed discussion in Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Induce WebDriverWait and wait for ElementToBeClickable.Hope this will work

 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); 
 wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("PaymentMethod_FullName"))).SendKeys(name);

OR

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); 
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Xpath("//fieldset[@class='payment-methods required-form']//ol[@class='form credit label-positioned']//li//input[@id='PaymentMethod_FullName']"))).SendKeys(name);
KunduK
  • 32,888
  • 5
  • 17
  • 41
-1

EDIT: It was a iframe, I'm just dumb

Just do driver.SwitchTo().Frame(driver.FindElement(By.Id("ID OF THE IFRAME HERE"))); and then it will work