0

I am using selenium with python and I try to click on element below. But every time shows the error (in starting was working) only getting error on this line and have tried CSS selector id and all HTML CODE::

<div class="uploadWrap">
                                                <input type="text" class="uploadInput ng-pristine ng-untouched ng-invalid ng-invalid-required" name="net_qty" ng-model="cauction.net_sell_qty" required="" required-param="true" valid-number="">
                                                <label class="upload-btn">MT</label>
                                            </div>

Selenium code::

quantity = wait.until(EC.presence_of_element_located((By.NAME, 'net_qty')))
quantity.send_keys('105')

Error ::

Traceback (most recent call last):
  File "C:/Users/Devesh/PycharmProjects/E-mandi/jj.py", line 76, in <module>
    quantity.send_keys('105')

Error::
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
    return self._parent.execute(command, params)
    self.error_handler.check_response(response)
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=81.0.4044.122)
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.18363 x86_64)
7
  • For which browser ? did you add wait before sending something to input element ? is there any pother element overlapping it ? is page still laoding ? is the element in view or you have to scroll to element ?
    – PDHide
    Apr 30 '20 at 18:36
  • @PDHide i have used Google chrome . yes i did use wait. i don't know much (if there overlapping element how to find them ? please let me know i am new. no page is not loading .no its just a input field. May 1 '20 at 4:27
  • try normal sleep for say 5 sec and see if you are able to sendkey ,is it a textbox ?
    – PDHide
    May 1 '20 at 5:36
  • yes its a input box for integer value only but , what i can see is that there are two element in the one field , please look above HTML code .. isn't that a problem? May 1 '20 at 5:56
  • What you mean by two elements in one field ? the html is fine and i am able to sendKeys . Makes sure ther are no other elements with the same name. Try using xpath or css like //input[@name="net_qty"]
    – PDHide
    May 1 '20 at 7:38
1

First, try with basic sleep:

//wait for 20 second
time.sleep(20)

// fetch the element
input = driver.find_element(By.XPATH,"//input[@name='net_qty']")

 // send value
 input.sendKeys(1);

If this work, it means the pages taking some time to load that's why it was failing. Then you can change time.sleep() into explicit wait using expected condition visbilityof.

If this doesn't work, read on:

The exception says element not visible:

so the first possibility is that the element is not in the viewport, means you cannot see element unless you scroll to that element. In this case use below code:

// fetch the element
input = driver.find_element(By.XPATH,"//input[@name='net_qty']")

// run JS to reveal the element   
driver.execute_script("arguments[0].scrollIntoView();",input);

// send file path keys
input.sendKeys(1);

The second possibility is that some other element may be hiding the element.

// fetch the element
input = driver.find_element(By.XPATH,"//input[@name='net_qty']")

// run JS to reveal the element   
driver.execute_script("arguments[0].style.display = 'block';", input);

// send file path keys
input.sendKeys(1);

Also, you can replace display value to the original value once the value is send:

// fetch the element
input = driver.find_element(By.XPATH,"//input[@name='net_qty']")

// display property will designed whether to bring 
// the element to front or keep in backround 
// we will save the current value to an element
display=driver.execute_script("return arguments[0].style.display", input);

// run JS to bring the element to foreground by setting display to block  
driver.execute_script("arguments[0].style.display = 'block';", input);

// send value
input.sendKeys(1);

//now replace the display value to the previous one: 
driver.execute_script("arguments[0].style.display = arguments[1];", input, display); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.