0

I'm having trouble having selenium locate an element on a website (gleam to be exact). Ideally I would like the driver to send keys to an input field, but selenium won't locate it for some reason.

I've already tried locating by ID, Xpath and by name. Any suggestions on how to locate this element?

Here's the html:

<input
  id="contestant[name]"
  name="name"
  ng-model-options="{ debounce: 300 }"
  ng-model="contestantState.form.name"
  ng-pattern=".*"
  placeholder="Alice Smith" required=""
  style="width: 246px"
  type="text"
  class="ng-empty
  ng-invalid
  ng-invalid-required
  ng-valid-pattern
  ng-dirty
  ng-valid-parse
  ng-touched"
>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ml2017
  • 1
  • 1
  • 4
  • Show us HTML of the element you are trying to locate. – Matthewek Apr 23 '19 at 07:21
  • Did you wait enough time for the element to appear on the page? – Mate Mrše Apr 23 '19 at 07:23
  • See: [How do I do X?](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) The expectation on SO is that the user asking a question not only does research to answer their own question but also shares that research, code attempts, and results. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [How to Ask](https://stackoverflow.com/help/how-to-ask) – S Ahmed Apr 23 '19 at 07:40

3 Answers3

1

Try one of these

By.CssSelector("[id*='contestant']")

By.CssSelector("[ng-model='contestantState.form.name']")

By.CssSelector("[name='name']")
Valga
  • 459
  • 2
  • 7
0

Use WebDriverWait to handle the dynamic elements on Web Page.Try following code. If this code not work check whether your input element inside any iframe.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium import webdriver

inputelement=WebDriverWait(driver,40).until(expected_conditions.element_to_be_clickable((By.ID,'contestant[name]')))
inputelement.send_keys("Apple")
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

To send a character sequence to the desired element as the element is an Angular element so you need to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.ng-empty.ng-invalid.ng-invalid-required.ng-valid-pattern.ng-dirty.ng-valid-parse.ng-touched[id=\"contestant[name]\"]"))).send_keys("ml2017")
    
  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='ng-empty ng-invalid ng-invalid-required ng-valid-pattern ng-dirty ng-valid-parse ng-touched' and @id=\"contestant[name]\"]"))).send_keys("ml2017")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352