How do I copy a text from a Web page and paste it into an input on another page, with java or Selenium WebDriver?
How do I copy a text from a Web page and paste it into an input on another page, with java or Selenium WebDriver?
Let's suppose that the ID of the 'copy here' is 'celphone-number'. And the 'paste here' is 'new-celphone-number'.
You will first get this element (copy here) usually through webelement + driver.findelement
, after which you will associate this new element with a String and use getattribute("Atributo que quer")
. In my case, I discovered the attribute like this:
<input id="celphone-number" class="phone depends" type="text" maxlength="11" **value**="9-8889-8989" name="celphone-number" data-depends="#check-sms"/>
Soon it was: getattribute("value")
.
At the end, I found the element responsible for the new phone field, and I used a sendkeys
sending the created variable. See the code that is easier to understand.
See below:
WebElement getphone = driver.findElement(By.id("celphone-number"));
String getphonetext = getphone.getAttribute("value");
WebElement newphone = driver.findElement(By.id("new-celphone-number"));
newphone.clear();
newphone.sendKeys(getphonetext);