4

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

2
  • 1
    Update the question with the error you see. Commented Feb 1, 2021 at 20:09
  • Done. The error is in the console log. Commented Feb 1, 2021 at 20:19

3 Answers 3

3

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=AutomationControlled

So 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]")

References

You can find a couple of relevant detailed discussion in:

Sign up to request clarification or add additional context in comments.

5 Comments

Still getting the same error. If I open the login page using selenium and I fill out the form manually it works. Even if I fill only the email using selenium and the password manually or only defining find_element_by_... I get the error.
@EmmaGrove Possibly due to zonal restrictrictions I get a Page Not Found even on accessing the page manually. Hence provided a few other references for your reference.
Thanks you so much for your help! The website is not available in some countries. Use USA Vpn if you have it if you don't I can give you mine
@EmmaGrove Sure. Let's discuss the issue in details within Selenium Chat Room
You didn't respond
0

I fixed this by using firefox geckodriver instead of chrome webdriver.

Comments

0

I got a CORS issue with Firefox geckodriver.
Here is what I did to fix the issue (using JavaScript / Node.js but the solution may be similar for Python).

Start geckodriver like this:
geckodriver --marionette-port 2828

Add the usingServer line to your code to listen on localhost:4444:

var driver = new webdriver.Builder()
    .usingServer("http://localhost:4444")
    .forBrowser("firefox")
    .setFirefoxOptions(options)
    .build();

Comments

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.