-1

I try to use:

action.sendKeys("some phrase with a dot, for example: www.google.co.il ");

but when i run the program what the action writes is:

www*google*co*il

the * represent hebrew character. I can disable this only by disabling the hebrew language in my computer.

I tried to bypass the problem by using JS: set.attribute but it makes a lot of problems and i need something better.

Is there a function similar to sendkeys or a way to fix it?

Sadegh
  • 865
  • 1
  • 23
  • 47

2 Answers2

0

You can try JavascriptExecuter using below code:

WebElement text= driver.findElement(By.name("q"));
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].value='test input';", text);

Webelement is the textbox where your need to write the value.

Or you can try some copy paste action after clicking into text box.

actions.click();

Refer to this URL for help: http://www.helloselenium.com/2015/03/how-to-set-string-to-clipboard-data.html

Abhishek Yadav
  • 459
  • 5
  • 16
  • thanks you for your solutions, for the first one: as i was saying using the Jsecuter will work some of the times but mostly it won't. setting the atribute or value is not an option for me. for your second solution: can you elaborate more ? if i copy paste my text will i still use sendkeys with the same text to the element? do you suggest using it instead of send keys? if so.. how? I read the link but it talks about copy paste into notepad.. how can i use something like this? thanks. Avinoam – Avinoam Ashkenazi Mar 26 '15 at 09:09
  • You can do same thing for copy paste like click into your editable webelement (textbox) and then copy-paste the content: webelement.click(); – Abhishek Yadav Mar 26 '15 at 10:23
  • Then paste the string: String string = "Hello Selenium"; StringSelection stringSelection = new StringSelection(string); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(stringSelection, null); try { Runtime runtime = Runtime.getRuntime(); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } catch (Exception e) { e.printStackTrace(); } – Abhishek Yadav Mar 26 '15 at 10:24
  • thank you for your solution. unfortunately the solution is not what i need. i need selenium to actually emulate the writinig so copy paste won't fix the problem for me. – Avinoam Ashkenazi Mar 27 '15 at 08:44
-1

I found out a way to change language during the tests while I solved another problem related to Upload a picture. there is this freeware called AuTOIT that you can use to help you with dialogs on Windows. I wrote a script to push the alt and click shift and my language is changed.

To change the language, I use the line:

Runtime.getRuntime().exec("path_of_script_here/name_of_script_here.exe");

The script was made the following way:

  1. Open a text file.
  2. Inside the file write:
    Send ("{ALTDOWN}") ;Hold down Alt Sleep(100) ;Wait 100 milliseconds Send("{LSHIFT}{ALTUP}") ;Press Left-Shift and release Alt
  3. Save as .au3 file.
  4. Download and install AUTOIT.
  5. Compile the script and then exe file will be created.
  6. Run the test.

Hope this will help everyone else who encounters this problem. If something is not clear, ask me and I will gladly help.

Brian
  • 14,610
  • 7
  • 35
  • 43