Focus Stuck In Form After Sending Keys

Hello New Relic Team,

I’m currently building a new Synthetic which is attempting to navigate to a checkout page, populate several inputs in a form and then click a submit button. The problem is that once I focus on the Input buttons I am unable to find my submit button afterwards. If I attempt to find the submit button element before focusing on and populating the various inputs I can do it successfully. Here is some example code of what I’m doing:

// Step 5 THIS IS THE PART THAT WORKS
.then(function() {
  log(5.1,'Scroll until "CONTINUE TO PAYMENT & BILLING" button visible')
  return $browser.executeScript("arguments[0].scrollIntoView(true);", $browser.findElement(By.id("submitButton")));
})

//Step 6 THIS IS THE INPUT I'M POPULATING IN A FORM
.then(function() {
  log(6.1,'Populate Phone')
  return $browser.waitForAndFindElement(By.id("phoneNumber"))
  .then(function(el) {
    el.clear();//clear out the input
    el.sendKeys("123-456-7890"); 
  })
})

// Step 7 THIS IS THE PART THAT FAILS
.then(function() {
  log(7.1,'Scroll until "CONTINUE TO PAYMENT & BILLING" button visible')
  return $browser.executeScript("arguments[0].scrollIntoView(true);", $browser.findElement(By.id("submitButton")));
})

I believe the problem is that I’m stuck in the “phoneNumber” input’s form after focusing it but I’ve been looking into ways to lose this focus and I’m at a bit of a loss. Any suggestions as to what’s going on and how to fix it?

1 Like

I figured it out, I simply had to change focus back to the base document.

All I had to do was add this before interacting outside the form:

$browser.switchTo().defaultContent();
1 Like

Hey @adrian.stratienco - Thank you so much for coming back to let us know how you solved the problem. You are a :star:!

Hi,

I am new to new relic selenium. This is really helpful to scroll down the page which you have mentioned it.

Thanks,
Dheeban D