How To reuse .getText value in another page Java Selenium

I am trying to use .getText and want to use that retrieved text, on another page(Search box).

Can I get any help?

I am using Java Selenium.

Thanks In advance.

1 answer

  • answered 2021-07-16 03:34 YaDav MaNish

    You can use the sessionStorage and store the text using getText() add data to the session storage and it will be accessible to any page from the same site opened in that window.

    String text = driver.findElement(By.xpath("//*[text()='Google offered in:  ']")).getText();
    WebStorage s = (WebStorage) new Augmenter().augment(driver);
    SessionStorage ss =s.getSessionStorage();
    ss.setItem("Text", text);    
    driver.findElement(By.name("q")).sendKeys(ss.getItem("Text"),Keys.ENTER);
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum