有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用selenium grid remote webdriver java client拍摄屏幕截图,并返回混乱的字符

我在一个linux平台上建立了一个selenium grid 2,集线器和节点都在同一台机器上。然后,我使用selenium remote webdriver(java客户端)拍摄了www.google的屏幕截图。通用域名格式。香港网页。结果是一团糟: enter image description here

所有的矩形字符都是汉字

LANG的系统环境变量是en_US。UTF-8,我用“-Dfile”启动了hub and node。encoding=“Unicode””。此外,我的Java代码是用UTF-8编码编写的

那么,有没有办法把这些杂乱的矩形字符转换成正确的原始字符呢


共 (1) 个答案

  1. # 1 楼答案

    您需要使用浏览器配置文件并在此处设置语言首选项。创建浏览器实例时,将配置文件作为参数传递。检查下面的代码:

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile profile = allProfiles.getProfile("Your-profile-name");
    profile.setPreference( "intl.accept_languages", "no,en-us,en" ); 
    FirefoxDriver driver = new FirefoxDriver(profile);
    driver.get("http://www.mysite.com/");
    
    注:我认为你已经知道了浏览器中的配置文件的概念。