-1

Using Java/Selenium and Page Objects, I have to create an item name that is auto generated using the current date and time and entered into a text field. I then have to verify that this item was created on a different page. I am storing the name (current date/time) in a string via locating the element and getting the value but at certain points this name will be a link that needs to be clicked.

How do I make the saved String name clickable?

Ex: Currently storing as String name = ad.name1.getAttribute("value")

Cannot execute name.click()

1
  • Could you provide the Dom for both the page
    – PDHide
    Jan 8 '20 at 7:17
1

I hope what you want to do is :

driver.findElement(By.partialLinkText(name)).click()

You already have the link text stored in the variable 'name' . So once you are in the target page , use above command .

0

After storing the name like String name = ad.name1.getAttribute("value") wait untill the value change to aclickable link. Then locate the same element with a different criteria and click on it.

1
  • That won't work because the created value is on one page and i need to find whatever the value is on a different page.
    – kylokyler
    Jan 8 '20 at 5:24
0

name is a String. It cannot be clicked. The only thing that can be clicked by Selenium is WebElement.

You need to find element by some locator that cointains 'name' and then click it.

Without DOM and your code is hard to guess how to fix it. It might be something like:

WebElement element = driver.findElement(By.xpath("//*[contains(text(), '" + name + "')]"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.