0

I have a problem with entering the email into the following website: https://isapps.acxiom.com/optout/optout.aspx#section8.

This is the code I use:

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.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
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)
    driver = webdriver.Chrome(options=chrome_options)
    driver.set_page_load_timeout(10)
    driver.set_window_size(1124, 850) # set browser size
    # link to data delete form
    print("opening data delete form")
    driver.get("https://isapps.acxiom.com/optout/optout.aspx#section8")
    #Select opt out segment: Following option values: "Mail", "Telemarketing", "Email"
    ele = driver.find_element_by_xpath("//select[@id='OptOutChoices2']/option[@value='Mail']") 
    driver.execute_script("arguments[0].click()",ele)
    print("dropdown selected")
    #Select identity: Following option values: "Myself", "Legal guardian", "Deceased person"
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//select[@id='Identity']/option[contains(text(),'Who is opting out?')]"))).click();
    #Select title: Following option values: "Mr.", "Mrs.", "Ms.", "Dr.", "Honorable", "Reverend", "Other"
    ele3 = driver.find_element_by_xpath("//select[@id='Title']/option[@value='Mr.']") 
    driver.execute_script("arguments[0].click()",ele3)
    driver.find_element_by_id("FirstName").send_keys(firstname) 
    driver.find_element_by_id("MiddleName").send_keys(middlename)
    driver.find_element_by_id("LastName").send_keys(lastname)
    driver.find_element_by_id("DDSuffix").send_keys(suffix) 
    driver.find_element_by_id("Email").send_keys(email) 
    # KEEP THIS DISABLED BC IT ACTUALLY SUBMITS 
    # driver.find_element_by_id("SubmitButton2").send_keys(Keys.ENTER)
    print("executed")
    time.sleep(4)
    driver.quit()
    return None

title = "Mr"
middlename = ""
firstname = "Joe"
lastname = "Musterman"
suffix = ""
email = "[email protected]"
acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email)

I get following error:

  Traceback (most recent call last):
  File "website-functions/acxiom.py", line 62, in <module>
    acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email)
  File "website-functions/acxiom.py", line 49, in acxiom_DD_formfill
    driver.find_element_by_id("Email").send_keys(email)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
  'value': keys_to_typing(value)})
 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
      (Session info: headless chrome=80.0.3987.87)

This is the HTML of the email field I try to access:

<div class="formsection " id="EmailSection">
                                <div id="EmailAddressPanel">

                                        <div onkeypress="javascript:return WebForm_FireDefaultButton(event, 'AddEmail2')">

                                            <div class="listPanel">
                                                <div id="EmailAddressInputGroup">
                                                    <table class="formsection-table">
                                                        <tbody><tr>
                                                            <td>
                                                                <input name="Email" type="email" maxlength="50" id="Email" class="form-control iEmail" placeholder="Email Address" novalidate="novalidate">
                                                            </td>
                                                            <td>
                                                                <span class="tooltip">
                                                                    <img src="images/img-question-mark-bubble.svg" alt="Email information">
                                                                    <span class="tooltiptext">Add all email address variations
                                                                    </span>
                                                                </span>
                                                            </td>
                                                            <td>
                                                                <input type="submit" name="AddEmail2" value="" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;AddEmail2&quot;, &quot;&quot;, true, &quot;EMail&quot;, &quot;&quot;, false, false))" id="AddEmail2" title="Add Email Address to list" class="btn btn-formsection invisible" alternatetext="Add Email Address to list">
                                                            </td>
                                                        </tr>
                                                    </tbody></table>

                                                    <span id="EmailRegexValidator" class="error-message" style="display:none;">
                                                        Please enter a valid email address.
                                                    </span>
                                                    <span id="AllowedCharactersInEmailValidator" class="error-message" style="display:none;">
                                                        Invalid characters have been removed.
                                                    </span>
                                                    <span id="SingleValidEmailValidator" class="error-message" style="display:none;">
                                                        Please enter a single valid email address.
                                                    </span>
                                                    <span id="EmailNotAddedValidator" class="error-message" style="display:none;">
                                                        Click the <img src="images/close.svg"> button to add the email entered above or clear the field(s) before Submitting form.
                                                    </span>
                                                    <span id="MaxEmailEntriesValidator" class="error-message" style="display:none;"></span>
                                                </div>
                                                <span id="OneEmailRequiredValidator" class="error-message" style="display:none;">
                                                    Please add at least one email address.
                                                </span>
                                                <div>

            </div>
                                            </div>

        </div>

    </div>
                            </div>

Is it correct that I need to interact with the following HTML element?

<input name="Email" type="email" maxlength="50" id="Email" class="form-control iEmail" placeholder="Email Address" novalidate="novalidate">

Thank you for your help!

2 Answers 2

1

The reason you are getting error because your first drop down is not selected the value email hence Email field is not generated.You need to select the email from drop down.Try below code.

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.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
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)
    driver = webdriver.Chrome(options=chrome_options)
    driver.set_page_load_timeout(10)
    driver.set_window_size(1124, 850) # set browser size
    # link to data delete form
    print("opening data delete form")
    driver.get("https://isapps.acxiom.com/optout/optout.aspx#section8")
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.ss-values"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.ss-values"))).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='ss-option' and contains(.,'Email')]"))).click()
    print("dropdown selected")
    #Select identity: Following option values: "Myself", "Legal guardian", "Deceased person"
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//select[@id='Identity']/option[contains(text(),'Who is opting out?')]"))).click();
    #Select title: Following option values: "Mr.", "Mrs.", "Ms.", "Dr.", "Honorable", "Reverend", "Other"
    ele3 = driver.find_element_by_xpath("//select[@id='Title']/option[@value='Mr.']")
    driver.execute_script("arguments[0].click()",ele3)
    driver.find_element_by_id("FirstName").send_keys(firstname)
    driver.find_element_by_id("MiddleName").send_keys(middlename)
    driver.find_element_by_id("LastName").send_keys(lastname)
    driver.find_element_by_id("DDSuffix").send_keys(suffix)
    WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,'Email'))).send_keys(email)
    #driver.find_element_by_id("Email").send_keys(email)
    # KEEP THIS DISABLED BC IT ACTUALLY SUBMITS
    # driver.find_element_by_id("SubmitButton2").send_keys(Keys.ENTER)
    print("executed")
    time.sleep(10)
    driver.quit()
    return None

title = "Mr"
middlename = ""
firstname = "Joe"
lastname = "Musterman"
suffix = ""
email = "[email protected]"
acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email)
Sign up to request clarification or add additional context in comments.

Comments

0

An alternative solution:

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.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
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)
    driver = webdriver.Chrome(options=chrome_options)
    driver.set_page_load_timeout(10)
    driver.set_window_size(1124, 850) # set browser size
    # link to data delete form
    print("opening data delete form")
    driver.get("https://isapps.acxiom.com/optout/optout.aspx#section8")
    #Select opt out segment: Following option values: "Mail", "Telemarketing", "Email"

    dropdown=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "ss-multi-selected")))
    dropdown.click()
    WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME,'ss-option')))
    list_options = driver.find_elements_by_class_name('ss-option')
    list_options[2].click()

    print("dropdown selected")
    #Select identity: Following option values: "Myself", "Legal guardian", "Deceased person"
    identity_dropdown = driver.find_element_by_id('Identity')
    select = Select(identity_dropdown)
    select.select_by_value('Submitter')

    #Select title: Following option values: "Mr.", "Mrs.", "Ms.", "Dr.", "Honorable", "Reverend", "Other"
    title_dropdown=driver.find_element_by_id('Title')
    select = Select(title_dropdown)
    select.select_by_value(title)

    driver.find_element_by_id("FirstName").send_keys(firstname)
    driver.find_element_by_id("MiddleName").send_keys(middlename)
    driver.find_element_by_id("LastName").send_keys(lastname)
    driver.find_element_by_id("DDSuffix").send_keys(suffix)
    driver.find_element_by_id("Email").send_keys(email)
    # KEEP THIS DISABLED BC IT ACTUALLY SUBMITS
    # driver.find_element_by_id("SubmitButton2").send_keys(Keys.ENTER)
    print("executed")
    time.sleep(4)
    driver.quit()
    return None

title = "Mr."
middlename = ""
firstname = "Joe"
lastname = "Musterman"
suffix = ""
email = "[email protected]"
acxiom_DD_formfill(title, firstname, middlename, lastname, suffix, email)

Some notes:

  • I found the execute_script approach failing on both Optout dropdown and Title dropdown (at least on my machine).
  • I have added the "Who is opting out" selection implementation.
  • Due to the particular DOM structure, a webdriver Select approach isn't possible for the Optout list, but it is certainly feasible for the Who is opting out and Title lists (see above).
  • At least when creating your script/debugging, it's a good idea NOT to run in --headless mode. This way you can see what your script actually does on the webpage, and it might help you understand better the errors you get (this question is a good example)

1 Comment

Thank you for your answer! I would love to run the code not in the headless mode. However, without the option, I get following error: ` File "other/acxiom-test.py", line 21, in acxiom_DD_formfill driver = webdriver.Chrome(options=chrome_options)` ... selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

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.