简体   繁体   中英

Selenium - Focus and Blur fails randomly on Firefox

I am testing on Firefox 55.0 Selenium 3.5.3 and I am having some trouble with Focusing on input element and after editing the text focusing out so the Client side validation can work and show error if needed.

javascriptExecutor.executeScript("document.getElementById('" + elementId + "').focus();");
javascriptExecutor.executeScript("document.getElementById('" + elementId + "').blur();");

this is the actual code.

Problem: The code works fine without any error but fails to show the error on random basis. I have webDriverWait for 5 seconds until the error shows up.

Any reason my code is failing on Firefox randomly???

Are you running multiple test with firefox simultaneously? If so, you could try to enable the flag focusmanager.testmode on the firefox profile. Check my answer here for more details.

Are you using Geckodriver to talk to the firefox instance?

I believe it has to do with the fact that Geckodriver does not start firefox with -foreground option.

Can you try adding firefoxOptions.addArguments("-foreground");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM