Is there a way to storetext within an element using watir webdriver and then paste it into another element?

98 views Asked by At

I'm trying to store text within an element. This text is dynamically generated. Is there a way to store text within an element using watir webdriver and then paste it into another element?

From all the research I have done, this is what I have come up with but do not know the command to paste the text within another element.

@browser.element(:css => 'div.confirmationMessage > span').text
2

There are 2 answers

1
Emjey On BEST ANSWER

I have had similar scenario where I have to upload a case and the case id is randomly generated which has to be verified the next page

In this case You store it in a variable and if you want the text to be pasted on an other field, just call this field n the element in send_keys

tostoretext = @browser.element(css: 'div.confirmationMessage > span').text
@browser.element(id: 'elementidentifier').send_keys(tostoretext)

if you want to call this outside of your function, make it accessibile with @

If you are using cucumber function for this, give the gherkin as:

Then I enter the text in identifier "elementidentifier" generated in identifier "div.confirmationMessage"

With the above gherkin, this is accessible within that cucumber function itself. Ensure the identifiers are correctly accessible.

0
titusfortner On

Based on what you have said, this is what it sounds like you are asking for, but I might not be understanding your question.

confirmation = @browser.span(css: 'div.confirmationMessage > span').text
@browser.text_field(id: 'txtExistingMemberPlan').set confirmation