Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to login due to language of web driver does not change #193

Open
victorviro opened this issue Nov 18, 2023 · 3 comments
Open

Fail to login due to language of web driver does not change #193

victorviro opened this issue Nov 18, 2023 · 3 comments

Comments

@victorviro
Copy link
Contributor

I specify the language when login: pinterest.login(lang="en"). But when driver goes to "https://pinterest.com/login"

driver.get("https://pinterest.com/login")
it redirects automatically to spanish version "https://www.pinterest.es/login/"

Then the login fails at looking for logins

logins = driver.find_elements(By.XPATH, "//*[contains(text(), 'Log in')]")
since the text to search is different ("Iniciar sesión" instead of "Log in")

@victorviro
Copy link
Contributor Author

This is due to the changing of the language of the driver is not working

chrome_options.add_argument("--lang=%s" % lang)

Adding this line chrome_options.add_experimental_option('prefs', {'intl.accept_languages': lang}) solves the problem

@victorviro
Copy link
Contributor Author

Anyway, I recommend use the english language. Otherwise logins may not be found

logins = driver.find_elements(By.XPATH, "//*[contains(text(), 'Log in')]")

due to the text to search may be different

@tuxlog
Copy link

tuxlog commented Jun 2, 2024

Running into the same issue I can confirm that changing the profile settings on Pinterest to country: US and language English solves this problem but will of course change your user experience in Pinterest to English. Hence I tried something different and change the login function in Pinterest.py to:

        ...
        driver = webdriver.Chrome(options=chrome_options)
        
        # select login url according to lang parameter
        login_url = "https://pinterest.com/login"
        if lang == "de":
            login_url = "https://pinterest.de/login"
        
        driver.get(login_url)

        try:
            WebDriverWait(driver, wait_time).until(
                EC.element_to_be_clickable((By.ID, "email"))
            )

            driver.find_element(by = By.ID, value='email').send_keys(self.email)
            driver.find_element(by = By.ID, value="password").send_keys(self.password)
            driver.find_element(by = By.ID, value="password").send_keys(Keys.ENTER)

            WebDriverWait(driver, wait_time).until(
                EC.invisibility_of_element((By.ID, "email"))
            )

            cookies = driver.get_cookies()
            ...

It is important to use the language specific login page, seems Pinterest does some magic in conjunction with the language setting in the profile. To be more independent from language specific web page content, instead of searching the element to click on the web-page, you can just send a key press for the return key.

This solution works for me using English or German and probably will work for other languages too, if you extend the if-clause determin the login_url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants