-1

Browser: Chrome

I am testing that when you click on a button, it becomes disabled (account selection). However, my check does not get executed until after the new page loads. I assume this is part of the browser's behavior. I've tried using execute script but that didn't change much.

Am I crazy?

  • I found a resolution for the time being which uses all javascript. It clicks the link and returns the state of the class list. This works for my uses, but I feel it's dirty. – Thomas Nov 3 '20 at 19:49
1

By default focus will change newly opened window , so change your focus to old window

String winHandleBefore = driver.getWindowHandle();

// Perform the actions to.open new tab

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

If it's opens in same tab,

Then

driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.SECONDS);

try {
  driver.get("http://url/to/my/slow/loading/page");
} catch (TimeoutException e) {
  // Ignore the exception.
}

//Validate , and set pageloadtimeout to normal which is 15 mins driver.manage().timeouts().pageLoadTimeout(900, TimeUnit.SECONDS);

Also try Page loading strategy.

  • It is not opening a new tab, same tab. I use this method for other stuff though. – Thomas Nov 3 '20 at 19:49
  • I found a resolution for the time being which uses all javascript. It clicks the link and returns the state of the class list. This works for my uses, but I feel it's dirty. – Thomas Nov 3 '20 at 19:49
  • You can reset the pagetimeout and then set it back – PDHide Nov 3 '20 at 19:52
  • I can't use page load strategy, as setting to none would involve a lot of fixes. this is a single set of tests, so not worth rewriting. ill post my solution. – Thomas Nov 3 '20 at 19:59
0

Solution that worked best for my situation was to click the element then return the new state. This may not work for your case, PDHide suggested a few good solutions. Issue is caused by webdriver waiting for the page to load.

        return wd.execute_script(
        f"var button=document.getElementsByClassName('elementclass');" +
        "button.click();" +
        "return button.className.includes('disabled');"
    )
  • This is not a good solution , you are triggering the click event using Jquery . It doesn't check whether the button is disabled or visible – PDHide Nov 3 '20 at 22:10
  • We're just using normal javascript, no jquery. We know it will be visible. We have tests that test that. The issue is just whether the button became disabled. This works exactly how we need it. That's why I pointed to your solutions, because they will likely fit other people' solutions. The big issue is once we click the item using WebDriver it doesn't return to our Python code until AFTER the new page loads. – Thomas Nov 3 '20 at 22:31
  • Once the button is disabled , run the command again you can see the script still passes – PDHide Nov 3 '20 at 22:33
  • 1
    We verified this works by changing the class it checks for it, failed as it should. This all runs at once. We have a test to validate when it's still enabled and when its disabled :) Both pass. Since you answered with a perfectly valid answer and one I'd use, I'm awarding you the answer. – Thomas Nov 3 '20 at 22:36
  • I meant this won't test whether clicking the button triggers a click event , you are skipping that part and directly triggering – PDHide Nov 3 '20 at 22:44

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.