0

I'm having a problem with Selenium2 using Firefox version 39.0 and Firefox webdriver while testing a page based on Apache MyFaces Trinidad 1.0.6.

When I imitate press on CheckBox, TextBox becomes visible, however, sendKeys doesn't work all the time, even if I wait until ExpectedConditions.presenceOfElementLocated or use Thead.sleep(x) (even though it's the worst case), Unable to locate or Not found in cache problems are being thrown.

Another problem - while clicking on tabs of page, some can be pressed and it works, and some while being pressed, Selenium just pretends to put "Mouse" on it and link is being showed in the bottom left corner. Double-press doesn't work either.

So is this some kind of AJAX background method that screws me up with cache problems and not clicking, or what?

My code:

public void bclick(String ids, int msec) 
{ 
    new WebDriverWait(driver, 25).until(ExpectedConditions.elementToBeClickable(By.id(ids))); 
    driver.findElement(By.id(ids)).click(); 
    waitTime(msec); 
} 

This is my main method for clicking on elements, however it is unstable sometimes with some buttons(simple html buttons).

  • Can you post the URL for this page, and your code? – FDM Jul 8 '15 at 9:15
  • Hello, i'm sorry, but I can't post page due to safety precaution, however i'm adding my code: public void bclick(String ids, int msec) { new WebDriverWait(driver, 25).until(ExpectedConditions.elementToBeClickable(By.id(ids))); driver.findElement(By.id(ids)).click(); waitTime(msec); } This is my main method for clicking on elements, however it works unstable sometimes with some buttons(simple html buttons). – Gediminas Tubelevicius Jul 8 '15 at 11:13
1

I also use the below to check for my jQuery.

((IJavaScriptExecutor)Driver).ExecuteScript("return jQuery.active");
  • 1
    How does this piece of code workout? – IAmMilinPatel Jul 13 '16 at 3:28
  • If you're using jQuery for your ajax requests it will tell you whether that has finished loading, you can have it loop and wait a set amount of times before you go looking for your elements – JohnnyTheJet Jul 15 '16 at 20:11
0

When I imitate press on CheckBox, TextBox becomes visible, however, sendKeys doesn't work all the time

Check out the official documentation on waits.

Another problem - while clicking on tabs of page, some can be pressed and it works, and some while being pressed, Selenium just pretends to put "Mouse" on it and link is being showed in the bottom left corner. Double-press doesn't work either.

Your DOM might be in a state of flux as you are trying to interact with it. After any action modifies the DOM your next step should wait for the element before interacting with it.

0

You can also use java script: document.readyState === "complete" to determine whether a page has loaded.

In addition to that, note that in many cases, using the Selenium Actions class for clicking on items is preferred over a direct driver.click() as it better simulates a real click.

0

Answer for waiting right amount of time for elements to be ready for interaction using Apache MyFaces Trinidad 1.0.6. is to execute java script code with JavascriptExecutor and check state of _Request Queue_ if it's ready:

public void ajaxWait() {
        Boolean state = (Boolean)((JavascriptExecutor) driver).executeScript("return TrPage.getInstance().getRequestQueue().getDTSState() == TrRequestQueue.STATE_READY");
        new WebDriverWait(driver, 180).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driver) {
                JavascriptExecutor js = (JavascriptExecutor) driver;
                System.out.println(js.executeScript("return TrPage.getInstance().getRequestQueue().getDTSState() == TrRequestQueue.STATE_READY"));
                return (Boolean) js.executeScript("return TrPage.getInstance().getRequestQueue().getDTSState() == TrRequestQueue.STATE_READY"); //     return jQuery.active == 0
            }
        });
        if (!state) {
            waitTime(500);
        }
     }

waitTime(long mills) method is a simple Thread.sleep() method used for waiting some time for page to fully load.

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.