Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Clicking on element after waitForAndFindElement


#1

More or less the same, this issue seems to have been raised couple of times, one of the most relevant place was this. However, after carefully read that, it doesn’t seem to solve my problem.

I have this react app which presents a form and I’m trying to write a test scenario. One of the span’s I’m clicking on the last instruction, is suppose to open an accordion on the same page. I kind of expected this code to work since implementation of waitForAndFindElement is based on wait elementLocated and wait elementIsVisible.

$browser.get(URL)
  .then(() => $browser.findElement($driver.By.xpath('//input[contains(@id, "vin_lpn")]')).sendKeys("AA32000"))
  .then(() => $browser.findElement($driver.By.xpath('//input[contains(@class, "submit-vin-lpn")]')).click())
  .then(() => $browser.waitForAndFindElement($driver.By.xpath('//span[contains(text(), "Vælg udstyrsvariant")]')))
  .then((el) => el.click())

This does not work in Synthetics, and does not trigger any errors.

After implementing waitForAndFindElement I ran this with node locally so I can use debugger. After trying many things, I came to the point where I sat a timeout in the last promise which made my setup to work as expected. However this triggers an error in Sysntethics. Here is the full code:

$browser.get(URL)
  .then(() => $browser.findElement($driver.By.xpath('//input[contains(@id, "vin_lpn")]')).sendKeys("AA32000"))
  .then(() => $browser.findElement($driver.By.xpath('//input[contains(@class, "submit-vin-lpn")]')).click())
  .then(() => $browser.waitForAndFindElement($driver.By.xpath('//span[contains(text(), "Vælg udstyrsvariant")]')))
  .then(() => {
    setTimeout(() => { $browser.findElement($driver.By.xpath('//span[contains(text(), "Vælg udstyrsvariant")]')).click() }, 500)
  })

The error I’m getting is:

NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

Seems like you cannot use $driver in a setTimeout. How can I fix this?


#2

Hi @radubogdan, that is strange that the first snippet does not work or create errors, this would indicate that the monitor is able to find and click that element. What does the Screenshot result show in this case? Would you mind sharing a permalink to an example of results from running that snippet so we can take a closer look? It will be interesting to see what exactly the monitor is doing here :slight_smile:


#3

Hi rdouglas,

Thanks for pitching in. If I share the permalink, I think it will start the monitor from that boilerplate and not with my tryouts. We can try, but first please check my screenshot and concerns:

1. did react get the chance to attach clicking handler to the span?

Could it be that since waitForAndFindElement is working on top of elementLocated and elementIsVisible the click() executes before react gets the chance to atttach all handlers so that clicking actually does something?

2. Wait/Timeout

On my second attempt, I tried to use setTimeout() which works locally. Is there an alternative for this in NewRelic Synthethics to make it wait X seconds?

Expected outcome

Expected outcome after clicking the element which says " Vælg udstyrsvariant" -> opens accordion.


#4

Thanks for sending on that information, as you have a ticket open for this issue as well i’ll troubleshoot through that and we can post our solution back here for other users :slight_smile: