Hi,
I am iterating through a list of webpage URLs.
On each iteration I visit a different webpage URL.
On each page visited I am trying to check if a word exists in the page title,and if it does I want to add a string to the clipboard, so that the user can manually paste (CTRL+V) the string into the active Selenium browser window.
Code:
String pageTitle = driver.getTitle();
while(true)
{
if(pageTitle.contains("ABC"))
{
System.out.println("The page title contains ABC, copying ABC text to clipboard");
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection("ABC"));
clipboard.setContents(transferable, null);
}
else if(pageTitle.contains("DEF"))
{
System.out.println("The page title contains DEF, copying DEF text to clipboard");
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection((String) tmp.get("DEF");
clipboard.setContents(transferable, null);
}
else
{
System.out.println("Neither ABC or DEF found in page title");
}
}
When I run the Java program however after the first iteration/page visit the text isn't being copied into the clipboard, it is blank on iteration number 2+.
Can anyone advise me why the clipboard is blank on iteration 2+? Instead of it containing the assigned string?
Many thanks for any help!