Copy page text and paste into another with JAVA or Selenium Webdriver

Asked

Viewed 2,289 times

2

How do I copy a text from a web page and paste it into an input on another page, with java or Selenium Webdriver?

inserir a descrição da imagem aqui

1 answer

1

Let’s assume that the copy ID is 'celphone-number'. And the paste ID is 'new-celphone-number'.

You will first take this element (copy from here) normally through webelement + driver.findelement, after that you will associate this new element to a string and use the 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 became: getattribute("value").

In 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.