'Running forced automated translation in Google Chrome and Edge. Translation not working
I am trying to run different web page translations in Google Chrome and edge.
This is the option I would want to use for all languages to English. I have tried the below code but it wouldn't force any translation.
options = Options()
prefs = {
"translate_whitelists": {"es": "en"},
"translate_whitelists": {"de": "en"},
"translate_whitelists": {"ja": "en"},
"translate_whitelists": {"ar": "en"},
"translate_whitelists": {"zh": "en"},
"translate_whitelists": {"hi": "en"},
"translate": {"enabled": "true"}
}
options.add_experimental_option( "prefs", prefs )
options.add_argument( "--lang=en" )
driver = Chrome( executable_path='/usr/local/bin/chromedriver', chrome_options=options )
I am still not able to get the page translation working. The translation widget appears but doesn't tranlsate anything. It is able to detect language as well.
I have already tried these solutions.
Automatic translation is disabled when using selenium in chrome
Solution 1:[1]
I had the same problem... but I found bruteforce solution:
import pyautogui
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
url = 'https://ifconfig.me/'
options = Options()
options.add_argument('--lang=fr') # set your language here
browser = webdriver.Chrome(options=options)
browser.get(url)
actionChains = ActionChains(browser)
actionChains.context_click().perform()
# here maybe problem. Debug it:
for i in range(3):
pyautogui.sleep(1)
pyautogui.press('up')
pyautogui.press('enter')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |