Chromedriver: How to translate a page using selenium?

后端 未结 1 609
轮回少年
轮回少年 2021-01-21 17:11

I need to translate a page from Japanese to English, using selenium in chrome browser. I tried different ways one of sample code snippet is as following

import j         


        
相关标签:
1条回答
  • 2021-01-21 17:37

    You need to enable translate and add target language ID to the whitelist {"from" : "to"}.

    "translate":{"enabled":"true"}
    "translate_whitelists": {"ja":"en"}
    

    in java:

    Map<String, Object> prefs = new HashMap<String, Object>();
    Map<String, Object> langs = new HashMap<String, Object>();
    langs.put("ja", "en");
    prefs.put("translate", "{'enabled' : true}");
    prefs.put("translate_whitelists", langs);
    options.setExperimentalOption("prefs", prefs);
    
    0 讨论(0)
提交回复
热议问题