Python Selenium webdriver: element not interactable: Element is not currently visible and may not be manipulated [duplicate]

别说谁变了你拦得住时间么 提交于 2020-03-25 18:19:43

问题


I have written following code to interact with the Acxiom website:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
import os
import time
def acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email):
    chrome_options = Options()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option('useAutomationExtension', False)
    river = webdriver.Chrome(options=chrome_options)
    driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
    driver.set_page_load_timeout(10)
    driver.set_window_size(1124, 850) # set browser size.
    # link to data delete form
    driver.get("https://isapps.acxiom.com/optout/optout.aspx#section8")
    #Select opt out segment: Following option values: "Mail", "Telemarketing", "Email"
    dropdown_optoutchoice= Select(driver.find_element_by_id("OptOutChoices2"))
    dropdown_optoutchoice.select_by_value('Mail')
    print("dropdown selected")
    # KEEP THIS DISABLED BC IT ACTUALLY SUBMITS 
    # driver.find_element_by_id("SubmitButton2").send_keys(Keys.ENTER) # submit button
    print("executed")
    time.sleep(4)
    driver.quit()
    return None

I am trying to select the Multiple Choice option "Mail" on following website https://isapps.acxiom.com/optout/optout.aspx#section8 within:

<select size="4" name="OptOutChoices2" multiple="multiple" id="OptOutChoices2" class="optOutChoices" tabindex="-1" data-ssid="ss-78884" style="display: none;">
        <option value="Mail">Mailing Addresses</option>
        <option value="Telemarketing">Phone Numbers</option>
        <option value="Email">Email Addresses</option>

    </select>

However, this produces following error:

opening data delete form
Traceback (most recent call last):
  File "website-functions/acxiom.py", line 38, in <module>
    acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email)
  File "website-functions/acxiom.py", line 24, in acxiom_DD_formfill
    dropdown_optoutchoice.select_by_value('Mail')
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/support/select.py", line 82, in select_by_value
    self._setSelected(opt)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/support/select.py", line 212, in _setSelected
    option.click()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
  (Session info: headless chrome=80.0.3987.87)

Thank you for your help!

-------EDIT 1------- I get the exact same error when running driver.find_element_by_xpath("//select[@id='OptOutChoices2']/option[@value='Mail']").click()

instead of

  dropdown_optoutchoice= Select(driver.find_element_by_id("OptOutChoices2"))
  dropdown_optoutchoice.select_by_value('Mail')

来源:https://stackoverflow.com/questions/60835480/python-selenium-webdriver-element-not-interactable-element-is-not-currently-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!