3

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("justtest0219@gmail.com")
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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Emma Grove
  • 148
  • 2
  • 11

2 Answers2

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("justtest0219@gmail.com")
    
  • 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("justtest0219@gmail.com")

References

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 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. – Emma Grove Feb 01 '21 at 21:22
  • @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. – undetected Selenium Feb 01 '21 at 21:25
  • 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 – Emma Grove Feb 01 '21 at 22:21
  • @EmmaGrove Sure. Let's discuss the issue in details within [Selenium Chat Room](https://chat.stackoverflow.com/rooms/223360/selenium) – undetected Selenium Feb 01 '21 at 22:29
  • You didn't respond – Emma Grove Feb 02 '21 at 10:07
0

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

Emma Grove
  • 148
  • 2
  • 11