How to slow down the speed of selenium?

6,774 views
Skip to first unread message

sirus tula

unread,
Jan 9, 2013, 12:33:13 PM1/9/13
to seleniu...@googlegroups.com
Hello Selenium Experts,

I just got this new CPU i5 processor with 4GB Ram, 3.40GHz.

While moving my selenium scripts wasn't that hard, I am having problem running it in a loop or multiple times.

Since it runs super-fast, 3 out of 20 times the script fails sending keys command text input value in the same field instead of its own respective field.

If i debug or run once or twice or thrice, it works perfectly.

I am thinking it's happening because it's running in lightning speed.

I think i remember we can control browser speed in watir. I am not sure if we could do that in Selenium-Java.


Any feedback/suggestions is appreciated.

--
 
- "If you haven't suffered, you haven't lived your life."
 
Thanks,
 
Sirus

Edwolb

unread,
Jan 9, 2013, 12:59:25 PM1/9/13
to seleniu...@googlegroups.com
Two approaches you can take are implicit or explicit waits.

Implicit waits tells Selenium to wait up to a certain amount of time between each command it if can't find the field its looking for.

Explicit waits involve telling your code to specifically wait for something after the first command is issued before the second one is issued.

In general, Selenium waits for page loads fairly well.  If your application is done using AJAX, then it relies on the user specifying what to wait for, otherwise it may very well continue execution without waiting for all the Javascript to execute first.

We use explicit waits in most places, because implicit waits end up slowing down tests a lot, and still end up causing failures once in a while.

--
Chris

sirus tula

unread,
Jan 9, 2013, 2:55:21 PM1/9/13
to seleniu...@googlegroups.com
Thanks for the suggestion, Chris.

However i have already applied explicit wait for the page to be loaded. Here's the small snippet of my code.

    driver.findElement(By.id("Next")).click(); //clicks the next button
    common.waitforElement(By.id("EmailAddress"));  //Explicitly waits until the page is loaded with the element
       
    driver.findElement(By.id("EmailAddr")).sendKeys(Properties.getNewUserName());      //enters email address
    driver.findElement(By.id("Pass1")).sendKeys(Properties.getNewPassword());  //enters password.


On the highlighted code with green color, 1 out of 10 times, it fails entering password in the email address field.

I'm not sure why it fails to recognize the other elements after certain time. Since the page is already loaded, I assume all the elements in the page is already present in the page.


Thanks
- Ash




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/UkgHj0aGHLwJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Edwolb

unread,
Jan 9, 2013, 3:53:54 PM1/9/13
to seleniu...@googlegroups.com
The only thing I can think of is that sometimes web pages do users a "favor" by auto selecting the username field so that users can just start typing instead of clicking on the username.  Sometimes selenium can race with javascript and the two can conflict, where selenium executes first, enters the username, goes to the password, then the javascript flips you back to the username.

--
Chris

tulsi.tester

unread,
Jan 10, 2013, 5:37:12 AM1/10/13
to seleniu...@googlegroups.com
Hi Sirus,

In selenium RC we have a method setSpeed(timeout) which slow down your every selenium command or method. But as per my knowledge there is no equivalent method available in webdriver. So we are enforced to write explicit wait methods. Consider following items

1. We cannot assume that all the elements are loaded, if page is loaded. This means even if the page is loaded you cannot assume that every element on the page is loaded. To handle this we need to wait for that element to loaded. This can be achieved by using explicit wait method. You have to write a custom method waitForElementPresent(String locator) with the following pseudo code:


void waitForElementPresent(String locator){

for (int second = 0;; second++) {
        if (second >= 60) fail("timeout");
        try { if (isElementPresent(By.xpath(""))) break; } catch (Exception e) {}
        Thread.sleep(1000);
    }

//Method for isElementPresent(By by)

boolean isElementPresent(By by){

private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;

Debasish Dutta

unread,
Jan 10, 2013, 5:38:18 AM1/10/13
to seleniu...@googlegroups.com
Selenium.setspeed();

Thanks
Debasish

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/GKQFm9VploUJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Thanks & Regards,

Debasish Dutta
Reply all
Reply to author
Forward
0 new messages