0

I have a site and I need to fill an input field. Only the field with 37.75 is causing a problem, it is not disabled it has a placeholder and I can interact with it easily myself, but when it comes to selenium, I can't.

I have tried:

self.driver.execute_script(f"document.getElementById('product_length').value='{str(depth10)}'")

This did nothing

pyperclip.copy(str(depth10))
self.driver.find_element_by_id("product_length").click()
pclip.paste()
self.driver.find_element_by_id("product_length").send_keys(str(depth10))

Every find_element_by_id() returned the exception:

selenium.common.exceptions.ElementNotInteractableException: Message: Element <input id="product_length" class="input-text wc_input_decimal" name="_length" type="text"> could not be scrolled into view

I used Expected Conditions & WebdriverWait with element_to_be_clickable() but it couldn't find it in 2 minutes

I also tried:

actions.move_to_element(element).perform()

and

driver.execute_script("arguments[0].scrollIntoView();", element)

enter image description here Image of the field

Image of the HTML: HTML

HTML

0

1 Answer 1

1

This error message...

selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view

...implies that the WebElement wasn't interactable when you invoked click() on it.


Solution

Ideally, to click on 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, "span.wrap > input#product_length[name='variable_length[1]']"))).send_keys(str(depth10))
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='wrap']/input[@id='product_length' and @name='variable_length[1]']"))).send_keys(str(depth10))
    
  • 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
    
Sign up to request clarification or add additional context in comments.

13 Comments

I used Expected Conditions & WebdriverWait with element_to_be_clickable but it couldn't find it in 2 minutes. I used XPATH and ID, btw the elements was clearly visible and I could click it with my mouse while it couldn't find with expected conditions
@Alper Here's what you can try. Chcek if scroll is needed to make the element appear in the window. If not that. Open developer tools. press CTRL+F check if typing the xpath shows the element, else your xpath is wrong. It may be right, but sometimes, scrollintoview is neccessary. Without looking at the website it's hit and miss.
@AbhishekRai Thanks for your help, my xpath is correct and I forgot to mention in the question that I also tried scrollIntoView, and actions.move_to_element(element).perform() but I still can't proceed
is there a shadow-root above your element? Did you check if it is a different iframe? Else, right click and copy the full xpath`. That's all I can think of.
@Alper checkout the updated answer and let me know the status
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.