0

I searched the web for quit some time, and i can't figure it out.

While using Selenium with the FirefoxDriver, can't perform actions on the text cuz i keep getting ???? instead of actual characters.

Source file example:

enter image description here

Java code:

WebDriver driver = new FirefoxDriver();

I have tried to use some profiles i found online - did not work.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( <something>, <something> );
profile.setPreference( <something>, <something> );
driver = new FirefoxDriver( profile );

I think the problem is in the default encoding of Firefox, witch is "western".
and i need it to be "UTF-8" , or changing according to the site.

All answers to the questions i saw, did not solve the problem.

3
  • yeah its hard form information provided please can you provide actual htl source code Commented Apr 8, 2016 at 5:43
  • Could you show screenshot of web that Firefox has rendered?
    – Buaban
    Commented Apr 8, 2016 at 6:02
  • link this is the site . Commented Apr 9, 2016 at 16:39

2 Answers 2

1

I'm 99% certain this is simply a matter of the OP not having a Hebrew font installed (e.g.) on their client machine.

After a bit of detective work, this site seems very close to the site being tested. It's not exactly the same, but I think it shows the difference having the right font has.

enter image description here

Of course, not having the right font doesn't stop you validating the server's output.

@Test
public void testHebrew() {
    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("https://yedion.yvc.ac.il");
    Assert.assertEquals( driver.getTitle(), "תחנת מידע לסטודנט המכללה האקדמית עמק יזרעאל");
}

is a quick way to verify that the server's output is correct, even if your web-client of choice can't render said output.

3
  • the Hebrew font is OK when i'm using the site. the problem is when i activate selenium - the source code is all question marks where the Hebrew characters suppose to be. Commented Apr 9, 2016 at 16:38
  • and yes, it's practically the same site. link Commented Apr 9, 2016 at 16:40
  • 1
    Irrespective of what the content looks like in View Source, have you tried running my working test (above)? Your page reports a Content-Type of UTF8 (which overrides any browser defaults), which should match the Java Unicode chars in my example. You shouldn't need any workarounds/hacks to test Unicode sites end-to-end. Commented Apr 9, 2016 at 17:00
1

Hi i have done a work around for the question the idea is that

1.First take all value inside the list(here i think you are getting ???? instead of actual charterers .)
2.Now save all values inside the text document which save all value in UTF-8 format
3.Now read those values from the text file (now they will print the way they are in web app)
4. Now perform your next operation

5.i have attached a sample piece of working code please have a look

   public static void main(String[] args) throws IOException, InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver","D:\\eclipseProject\\StackOverFlow\\chromedriver_win32 (1)\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Ftab%3Dwm");

        // below in the right corner there is a Drop-down with values of languages for different country
        // take them all inside the list
        List<WebElement> myddval = driver.findElements(By.xpath("//*[@id='lang-chooser']/option"));
        System.out.println(myddval.size());

        // print the last value inside the dd on to the console
        System.out.println("DD value before Change (ANSI format) : "+ myddval.get(myddval.size()-1).getText()); // will print ???? in the console
        // now create a text document which saves its content form ANSI to UTF-8 format
        writer = new PrintWriter("C:\\Users\\rajnish\\Desktop\\name.txt", "UTF-8");
        // writing only the last value form dd in the text document = 繁體中文
        writer.write(myddval.get(myddval.size()-1).getText());
        System.out.println("value in the dd is : " + myddval.get(myddval.size()-1).getText());
        writer.close();
        // reading the value and printing it in the console now it will print =  繁體中文
        bufferedReader = new BufferedReader(new FileReader("C:\\Users\\rajnish\\Desktop\\name.txt"));
        System.out.println("Reading Text after converting it to UTF-8 Encoding : "+ bufferedReader.readLine());

        // now performing some action
        driver.findElement(By.id("lang-chooser")).click();
        Thread.sleep(2000);
        myddval.get(myddval.size()-1).click();

    }
2
  • great idea, already tried something similar. sadly, not working for WebDriver driver = new FirefoxDriver(); . Commented Apr 9, 2016 at 16:54
  • thanks @sahar Milis i have not tried with firefox but i think it will work for firefox even Commented Apr 9, 2016 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.