0

I'm using selenium 4.1.0 and I'm trying to send 'CRISTIAN' in an input bar through

input_bar.send_keys('CRISTIAN')

But it shows 'CISTIAN' in the bar. I've tried also tried:

ActionChains(driver).click(input_bar).send_keys('CRISTIAN', Keys.ENTER).perform()` 

But I get the same result. I checked all the uppercase letters and I figured out that only R have this problem. Any suggestions? Does it depends on this version of Selenium?

HTML of the input bar:

<div _ngcontent-qhp-c128="" cdkdroplist="" cdkdroplistorientation="horizontal" cdkdroplistdisabled="" class="cdk-drop-list d-flex flex-1 cdk-drop-list-disabled" id="cdk-drop-list-16"><input _ngcontent-qhp-c128="" cdkdrag="" data-bp="input" class="cdk-drag comp-input mt-2 cdk-drag-disabled" placeholder="Aggiungi elemento"><!----><!----><!----><!----></div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
marco
  • 525
  • 4
  • 11
  • Can you try assigning value to the input_bar using JS in browser console? – Rohit Babu Mar 09 '22 at 11:17
  • @RohitBabu yes, it works with JS in the browser console – marco Mar 09 '22 at 11:29
  • Could you show your HTML DOM or if possible share the website link. I tried with Google's searchbar, and it worked. Also, is there any specific reason to use such a long way (using action chains). You could send input directly as well, like this: `driver.find_element(By.XPATH, "your_element").send_keys('CRISTIAN')`. XPATH is one of the strategies, but any other locator strategy may also be used. – Anand Gautam Mar 09 '22 at 12:09
  • @AnandGautam I've attached the HTML. I find the element through XPATH and I use send_keys but I get the same problem – marco Mar 09 '22 at 12:14
  • @marco please use code format (copy paste the code) for HTML instead of img format – Anand Gautam Mar 09 '22 at 12:23
  • @AnandGautam did it – marco Mar 09 '22 at 12:26
  • @marco It works for me: `x = driver.find_element(By.TAG_NAME, "input") x.send_keys('CRISTIAN') y = x.get_attribute('value') print(y)` . Here is the output: `CRISTIAN Process finished with exit code 0`. I suspect there could be system setting in your machine that's affecting you, but I am not sure of it. – Anand Gautam Mar 09 '22 at 12:35
  • @AnandGautam I use macOS Monterey 12.1, Chrome 99.0.4844.51, webdriver v99 – marco Mar 09 '22 at 13:58

1 Answers1

0

The desired element is a Angular element, to send a character sequence 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[id^='cdk-drop-list'][cdkdroplistorientation='horizontal'] input[class*='cdk-drag'][data-bp='input'][placeholder='Aggiungi elemento']"))).send_keys('CRISTIAN')
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@cdkdroplistorientation='horizontal' and starts-with(@id, 'cdk-drop-list')]//input[contains(@class, 'cdk-drag') and @data-bp='input'][@placeholder='Aggiungi elemento']"))).send_keys('CRISTIAN')
    
  • 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