Hi I've been stuck for awhile on automating login for apple appstore as I am trying to make it headless without seeing the browser on execution.The problem is on execution with headless option and other options overall it doesn't find the field for appleid saying:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="account_name_text_field"]"}
This is the code I tried so far:
options = selenium_chrome()
options.add_argument("--enable-javascript")
options.add_argument('headless')
options.add_argument('--window-size=1920x1080')
options.add_argument('--start-maximized')
options.add_argument("--disable-notifications")
options.add_argument('--no-sandbox')
options.add_argument('--verbose')
options.add_experimental_option("prefs", {
"download.default_directory": DOWNLOAD_DIR,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing_for_trusted_sources_enabled": False,
"safebrowsing.enabled": False
})
options.add_argument('--disable-gpu')
options.add_argument('--disable-software-rasterizer')
driver = webdriver.Chrome('/path/to/chromedriver', chrome_options=options)
driver.get('https://appstoreconnect.apple.com/login')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
time.sleep(10)
f = driver.find_element_by_id("aid-auth-widget-iFrame")
driver.switch_to.frame(f)
# driver.implicitly_wait(15)
time.sleep(20)
driver.find_element_by_id('account_name_text_field').send_keys('appleid')
driver.find_element_by_id("sign-in").click()
time.sleep(5)
driver.find_element_by_id('remember-me').click()
time.sleep(3)
driver.find_element_by_id('password_text_field').send_keys('password')
driver.find_element_by_id("sign-in").click()
Notes:
I have tried getting the XPATH and CSS selectors instead of the ID and the result was the same.
Instead of
time.sleep()
I tried:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='account_name_text_field']"))).send_keys('appleid')
and the result was TimeoutException
- Did a retry function,whenever the field is not found to keep trying until it is found, but that was kind of a bad approach and it didn't worked.
So I am out of ideas what causes this behavior,the field is being found without the options for selenium and it logins fine visually, but whenever options are being added it doesn't find the input text field for appleid
anymore... Might be an Apple thing that I don't know.