How to type text into GUI elements

Asked by Vinu

Actualy i tried to upload a file using sikuli selenium.
After opening the upload window, sikuli is not working.
After closing the web page , the document path is appearing in Ide Console.

driver = new FirefoxDriver();

 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("http://www.toolsqa.com/automation-practice-form");
 driver.manage().window().maximize();
 WebElement d = driver.findElement(By.id("photo"));
 d.click();
 Thread.sleep(5000);

       Screen s = new Screen();
       App.focusedWindow();

       Pattern m_upload = new Pattern("D:\\Sikuli\\file.png");
       s.wait (m_upload, 3);
      s.type("path");

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this does nothing, but returns the region of the frontmost window
       App.focusedWindow();

so a possible usage:
       reg = App.focusedWindow();

       Pattern m_upload = new Pattern("D:\\Sikuli\\file.png");
       s.wait (m_upload, 3);

since you do not have any function before, that gives focus to the element, where you want to type, type will type to whatever GUI element has focus in the moment (apparently your IDE window)
      s.type("path");

I guess, this would be sufficient (having had a short look on the interesting webpage):

App.focus("Firefox");
reg = App.focusedWindow();
Pattern m_upload = new Pattern("D:\\Sikuli\\file.png");
reg.wait (m_upload, 3);
// give input focus to the entry field
reg.click(); // supposing a suitable click target
s.type("path");

Revision history for this message
Vinu (vinmyozon) said :
#2

Thank you for helping me..But still i cant get the result..

After clicking web element "d" its opening a file explore and i need choose file from there.
So i am giving a path in the "Filename" area and i need click on the "Open" button .
plzz help me.

driver.manage().window().maximize();
     WebElement d = driver.findElement(By.id("photo"));
       d.click();
       Thread.sleep(5000);

       Screen s = new Screen();
       App.focus("File Explorer");
       Region reg = Region(3,0,687,482);
       reg = App.focusedWindow();

       Pattern m_dropdown = new Pattern("D:\\Sikuli_Image\\file_name_path.png");
       reg.wait (m_dropdown, 3);
        s.type("C:\\Users\\vinumonp\\Desktop\\Bug");

Revision history for this message
RaiMan (raimund-hocke) said :
#3

sorry, but this are Sikuli basics and I do not have the time to write your code.

to be able to type anything to anywhere, you always have to take care, that the GUI element has focus (has an input cursor, ready to accept keyboard input).

To give focus to any GUI element, you have to do the same as manually:
click(the _correct_place); // usually inside the textfield
type("whatever");

or you might as well use the TAB key to jump from GUI element to GUI element if this is more suitable.

Can you help with this problem?

Provide an answer of your own, or ask Vinu for more information if necessary.

To post a message you must log in.