1

I am automating some web process but ran into some strange issue using selenium. I have:

<div data-field-name="incident_type_ids" style=""><div class="form-group" data-field-name="incident_type_ids">
  <label class="col-xs-4 control-label">
    Incident Type
    <i class="fa fa-info-circle" rel="tooltip" title="" data-placement="right" data-original-title="The type of incident (On Closure please verify that the original type was valid)"></i>
  </label>
  <div class="col-xs-8 controls">

    <span class="editmode">
      <select name="incident_type_ids" multiple="multiple" data-placeholder="Choose Some Types" class="chosen" style="display: none;"><option class=" " value="1007" title="Asset Theft/Loss">
  Asset Theft/Loss


<ul class="chosen-results"><li class="active-result" data-option-array-index="0" title="Dog">
  Dog
</li><li class="active-result  " data-option-array-index="1" title="Cat">
  Cat
</li><li class="active-result  " data-option-array-index="2" title="Mouse">
  Mouse
</li><li class="active-result  " data-option-array-index="3" title="Hunting">
  Hunting
</li><li class="active-result  " data-option-array-index="4" title="Information">
  Information
</li><li class="active-result  " data-option-array-index="5" title="Intelligence">
  Intelligence
</li><li class="active-result  " data-option-array-index="6" title="Request">
  Request
</li><li class="active-result  " data-option-array-index="7" title="Sky">
  Sky
</li><li class="active-result  " data-option-array-index="8" title="Phishing">
  Phishing
</li><li class="active-result  " data-option-array-index="9" title="Violation">
  Violation
</li><li class="active-result  " data-option-array-index="10" title="DDoS">
  DDoS
</li><li class="active-result  " data-option-array-index="11" title="Engineering">
  Engineering
</li><li class="active-result  " data-option-array-index="12" title="Intrusion">
  Intrusion
</li></ul>

And if I click and select value with WebDriverWait

WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@data-field-name='incident_type_ids']"))).click()
WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//ul[@class='chosen-results']//li[contains(.,'Phishing')]"))).click()

I get error:

selenium.common.exceptions.ElementNotInteractableException: Message: Element <li class="result-selected"> could not be scrolled into view

It does not make any sense, because if I replace Phishing with Any other value from the drop down menu it works. So why does it only get stuck at Phising? It's not even far scroll, if I replace it with Intrusion it still works too

1 Answer 1

1

The error suggest that you need to scrolled to the element.You can achieve that in selenium.

Try below options.

1 Use javascript executor to scroll.

WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@data-field-name='incident_type_ids']"))).click()
element=WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//ul[@class='chosen-results']//li[contains(.,'Phishing')]")))
driver.execute_script("arguments[0].scrollIntoView()", element)
element.click()

2 Use selenium property location_once_scrolled_into_view.

WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@data-field-name='incident_type_ids']"))).click()
element=WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//ul[@class='chosen-results']//li[contains(.,'Phishing')]")))
element.location_once_scrolled_into_view
element.click()

If you get any error something like NOT clickable at this point then use JS to click on the element.

WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@data-field-name='incident_type_ids']"))).click()
element=WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,"//ul[@class='chosen-results']//li[contains(.,'Phishing')]")))
element.location_once_scrolled_into_view
driver.execute_script("arguments[0].click();", element)
Sign up to request clarification or add additional context in comments.

Comments

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.