0

Hello i am new to selenium and self learning. My question is for the below webpage. I want the python program to enter some data into the search field.

I have tried various versions of samples i could find here but unable to understand what i am doing wrong here.

  1. enter_customer_name = driver.find_element("id" ,r"vaadin-text-field-input-0")
  2. enter_customer_name = driver.find_element(By.CSS_SELECTOR, "vaadin-text-field-container")
  3. driver.find_element("id","vaadin-text-field-label-0") enter_customer_name.send_keys("TEST")
  4. enter_customer_name = driver.find_element(By.CSS_SELECTOR, "name")

HTML snapshot:

enter image description here

Not sure what i am doing wrong. Any suggestions?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
gautam raj
  • 11
  • 3

1 Answers1

0

Given the HTML:

html

to enter some data into the search field instead of the <div> you need to traverse a bit deeper to the <input> tag.


Solution

To send a character sequence to the element ideally 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(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.vaadin-text-field-container div[part='input-field'] slot[name='input'] > input[part='value']"))).send_keys("text")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='vaadin-text-field-container']//div[@part='input-field']//slot[@name='input']/input[@part='value']"))).send_keys("gautamraj")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for the suggestions. I am getting a Timeout error when i tried to run it with above suggestion. " raise TimeoutException(message, screen, stacktrace) TimeoutException" – gautam raj Mar 09 '23 at 08:20
  • As there is a class in the first div should i add the class as well? div[class='vaadin-text-field-container'] div[part='input-field'] slot[name='input'] > input[part='value'] Is this a correct way to parse into the inner loop? – gautam raj Mar 09 '23 at 08:28
  • File "C:/Users/s7578437/.spyder-py3/Selenium_Mock.py", line 29, in WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.vaadin-text-field-container div[part='input-field'] slot[name='input'] > input[part='value']"))).send_keys("TEST") File "C:\Users\s7578437\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 95, in until raise TimeoutException(message, screen, stacktrace) TimeoutException – gautam raj Mar 09 '23 at 08:49
  • Still getting the same error for both the methods. – gautam raj Mar 09 '23 at 08:50
  • Check if the desired element is within an [**iframe**](https://stackoverflow.com/a/53276478/7429447) or within a [**shadowRoot**](https://stackoverflow.com/a/73242476/7429447) – undetected Selenium Mar 09 '23 at 08:54
  • It is within a Shadowroot. – gautam raj Mar 09 '23 at 09:01
  • @gautamraj You already have the link to the detailed explaination. Do you still need help? – undetected Selenium Mar 09 '23 at 09:04
  • I will give the link you provided a try and see if the shadowRoot can be parsed. Thank you so much for the suggestion. – gautam raj Mar 09 '23 at 09:06
  • Hi i am unable to come up with a right logic to parse the shadow root to the input where i am able to enter any text. shadow = Shadow(driver) shadow_host = shadow.find_element('#vaadin-text-field-container') value = "TEST" driver.execute_script("arguments[0].setAttribute('value',arguments[1])",shadow_host, value) Am i using the logic wrong? – gautam raj Mar 09 '23 at 14:44