Setting a text field that has a JQuery mask on it

前端 未结 2 1769
长情又很酷
长情又很酷 2021-01-27 11:05

Using watir-webdriver, I am trying to set the value for a text field.

browser.text_field(:id, \"phoneNumbers_value_input\").set(\"5555551234\")

2条回答
  •  爱一瞬间的悲伤
    2021-01-27 11:19

    The problem has to do with focusing on the text field. Even with a .click() somehow webdriver ends up with the cursor at the end if the input field (see issue 2377). Pressing the HOME key moves the cursor to the beginning and allows you to type in the input field, and still have the mask functionality.

    In Java:

    WebElement txtPhone = getDriver().findElement(By.id("phoneNumbers_value_input"));
    txtPhone.sendKeys(org.openqa.selenium.Keys.HOME);
    txtPhone.sendKeys(phoneNumber);
    

提交回复
热议问题