I'm trying to login to my dvd.netflix account using Selenium Python but I keep getting incorrect login information (despite entering the correct username and password) because the auth request failed due to cors error.
This is the code I'm using:
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://dvd.netflix.com/SignIn')
username_input = '//*[@id="email"]'
password_input = '//*[@id="password"]'
login_submit = '//*[@id="signin"]/button'
driver.find_element_by_xpath(username_input).send_keys("[email protected]")
driver.find_element_by_xpath(password_input).send_keys("12345")
driver.find_element_by_xpath(login_submit).click()
The error I get:
Access to XMLHttpRequest at 'https://portal.dvd.netflix.com/auth/authenticate' from origin 'https://dvd.netflix.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I also tried to disable CORS Check but still can't login, If I try to login manually with WebDriver for Chrome it does login
Possibly you are trying to invoke send_keys() too early even before the JavaScript enabled webelements have completely rendered.
To send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using XPATH:
driver.get('https://dvd.netflix.com/SignIn')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']"))).send_keys("[email protected]")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
In-case the error still occurs you may require to add the following argument:
--disable-blink-features=AutomationControlledSo your effective code block will be:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://dvd.netflix.com/SignIn')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']"))).send_keys("[email protected]")
You can find a couple of relevant detailed discussion in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With