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("AddEmail2", "", true, "EMail", "", 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!