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).

Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
asked Jul 8, 2015 at 7:41
2
  • Can you post the URL for this page, and your code? Commented Jul 8, 2015 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). Commented Jul 8, 2015 at 11:13

4 Answers 4

1

I also use the below to check for my jQuery.

((IJavaScriptExecutor)Driver).ExecuteScript("return jQuery.active");
answered Jul 11, 2016 at 20:52
2
  • 1
    How does this piece of code workout? Commented Jul 13, 2016 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 Commented Jul 15, 2016 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.

answered Jul 16, 2015 at 18:18
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.

answered Dec 14, 2015 at 4:07
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.

Eugene S
4291 gold badge6 silver badges18 bronze badges
answered Jul 8, 2015 at 11:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.