简体   繁体   中英

Java Selenium Firefox Driver - Textbox Onchange Issue

Running Java/Selenium 2.3 (and 4) using Firefox Driver on centos

Trying to test against a site that has form with a text type, with an onchange. Tried to insert the text using the sendkeys, and then changing focus by doing a select/click on another term in the form. Tried to do a fireevent as well. (Doesn't appear to be supported in the 2.3 sel)

Searched the net as well with no luck.

Basically, trying to get a solution to how to do an insert into a textbox for selenium/firefox driver, so the inserted text actually appears in the textarea, which means the onchange event gets fired.

The test html is::

<td rowspan='4' nowrap='nowrap'  valign='top' align='left'>
<DIV id='win0divCLASS_SRCH_WRK2_SUBJECT$69$'><input type='text' name='CLASS_SRCH_WRK2_SUBJECT$69$' id='CLASS_SRCH_WRK2_SUBJECT$69$' tabindex='31' value=""  class='PSEDITBOX' style='width:60px; ' maxlength='8' onchange="addchg_win0(this);oChange_win0=this;"  />
</DIV></td>

The test code is::

        driver.findElement(By.name("CLASS_SRCH_WRK2_SUBJECT$69$"))
            .sendKeys("ACG");
        driver.findElement(By.name("CLASS_SRCH_WRK2_SUBJECT$69$"))
            .sendKeys("");


        Select sCourse= new Select(driver.findElement(By.id("CLASS_SRCH_WRK2_ACAD_CAREER")));
        sCourse.selectByValue("");

The test sets the textelement, and then sets the select/option of a select item, which should trigger the change in focus. I also tried to clear, and reset the text, thinking that might trigger the onchange..

A solution to this would help a lot of people who've been looking for the same thing!!

Thanks

I had a similar problem (though my trigger was onBlur). I called the blur() method directly. In your case it would be

driver.findElement(By.name("CLASS_SRCH_WRK2_SUBJECT$69$")).sendKeys("ACG");
((JavascriptExecutor)driver).executeScript( "$('[name=\"CLASS_SRCH_WRK2_SUBJECT$69$\"]' ).blur() );

You might need a different function other than blur().

Have you tried doing a tab after sendKeys? You can do a driver.findElement(By.name("CLASS_SRCH_WRK2_SUBJECT$69$")) .sendKeys("\\t");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM