0

enter image description here

I am trying to type into the input category using selenium on Python google chrome. I would like to send the keys 1234 to test the configuration, however, I am receiving errors. I believe I am missing something from the code... Sorry if this is super basic, I am still learning selenium... I tried using the @class already and received an error.

driver.find_element_by_xpath("//input[='']/parent::div").send_keys('1234')

I am getting this error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[9]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div[1]/div[1]/div/input"}   
(Session info: chrome=88.0.4324.150)

I have concluded the html should represent value=1234, however, I still am struggling with the code.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
ghost
  • 27
  • 7
  • Firstly, what errors, second try right clicking in inspector then Copy>Copy full xpath. – Rocket Nikita Feb 18 '21 at 06:36
  • I'm need to type where the value is; I am struggling with this... Here's the xpath: `/html/body/div[9]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div[1]/div[1]/div/input` – ghost Feb 18 '21 at 06:38
  • I think the problem is your xpath is incorrect. Correct your xpath will solve the problem. – Trinh Phat Feb 18 '21 at 06:44
  • paste that xpath instead of the old one – Rocket Nikita Feb 18 '21 at 06:45
  • Can you post html in text format instead of image and part of your code as well ? It easier for us to give you correct answer. Link to the website you are working with even better. – Trinh Phat Feb 18 '21 at 06:47
  • I am getting this error `selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[9]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div[1]/div[1]/div/input"} (Session info: chrome=88.0.4324.150)` – ghost Feb 18 '21 at 06:48
  • Check if it's in a iframe or shadow root. – Arundeep Chohan Feb 18 '21 at 07:02
  • Why to use full xpath?...You can use relative xpath. For start use https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo . And try some tutorial with selectors like: https://www.guru99.com/locators-in-selenium-ide.html – Gaj Julije Feb 18 '21 at 07:07

1 Answers1

0

To send a character sequence to the element you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.find_element(By.CSS_SELECTOR, "input.[aria-label='Amount'][placeholder='0']").send_keys("1234")
    
  • Using XPATH:

    driver.find_element(By.XPATH, "//input[@aria-label='Amount' and @placeholder='0']").send_keys("1234")
    

The desired element is a dynamic element, so ideally to send a character sequence to the element 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, "input.[aria-label='Amount'][placeholder='0']"))).send_keys("1234")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@aria-label='Amount' and @placeholder='0']"))).send_keys("1234")
    
  • 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
    

References

You can find a couple of relevant discussions on NoSuchElementException in:

DebanjanB
  • 118,661
  • 30
  • 168
  • 217