0

I'm learning how to use Selenium Webdriver(RemoteWebDriver) and I'm having some problems with a page I'm training on because I can't click anywhere and I can't locate any element on the webpage.

I think the webpage is developed by using Spring or maybe Ajax and that's why I can't get to click anything.

This is the url: http://tinyurl.com/d9x453

For example, I'm not capable even to press the first button you can see on the webpage, Am I losing something?

Please, I'd really appreciate it If someone could help me.

Regards-

user3280424
  • 167
  • 3
  • 13
  • The problem must be directly with the selenium I'm using because I'm also trying to test another webpage and the remote webdriver I'm using doesn't locate any element on any webpage I'm using. – user3280424 Jul 29 '14 at 16:36
  • I was looking at the website and I think I can help you more if you tell me the what exactly you are trying to do. Like highlight something and click on a specific button etc. – Saifur Jul 29 '14 at 22:07
  • WebDriverWait wait = new WebDriverWait(driver, 60);// 1 minute wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("fieldset#search-bottom > button"))); WebElement searchButton = driver.findElement(By.cssSelector("fieldset#search-bottom > button")); searchButton.click(); By doing that I'm not getting to click on that button but the whole form where you can see the selects and the buttons – user3280424 Jul 30 '14 at 07:53

3 Answers3

0

I just need to wait for javascript execution. You may do that by checking some control and if it is null set some Thread.sleep(1000);

  • Hi and thank you for your answer, How CAn I wait for javascript execution? I mean because thread.sleep even though I set "a long time" the webpage isn't loaded completely and I've also used waits and It's not working. – user3280424 Jul 29 '14 at 15:31
0

Also Try with selenium.fireEvent("id=search-bottom", "blur").[Note havn't tested the code]

Which browser are you trying?

This is the code I wanted to share :

private WebElement searchButton;

@Test
public void testYourSearchClick(){
     final FirefoxDriver ffDriver = XXYOURUtillyClassForDriver.createFirefoxDriver();
     try{
      ffDriver.get(System.getProperty("selenium.baseURL"));

    searchButton= ffDriver.findElement(By.xpath("//fieldset[@id='search-bottom']"));//or your   //button class
    searchButton.click();
}catch(SeleniumException e){
      e.printStackTrace();
    }
}
Madhu Bose
  • 371
  • 4
  • 16
  • I've used firefox 18.0.1 and also 14 (the previous one I had) the funny thing, is If you open the webpage normally even with selenium ide plugin of firefox you can click on the buttons, etc. However (I'm using selenium webdriver) when the webpage loads I can't reach to any elements of the webpage. I think the sentence you sent is not useful for selenium webdriver no? – user3280424 Jul 29 '14 at 15:48
  • Sorry , what made me think Selenium RC ..my bad.Try WebElement element = driver.findElement(By.id("search-bottom")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element); – Madhu Bose Jul 29 '14 at 15:52
  • Also one more way .In my testcase I had used the below lines :private WebElement searchButton ;searchButton =driver.findElement(By.xpath("//fieldset[@id='search-bottom']"));searchButton.click() – Madhu Bose Jul 29 '14 at 15:53
  • Thank you very much M B but It doesn't seem to work neither of them :( – user3280424 Jul 29 '14 at 15:58
  • Hi again M B :), that's what I used and the code doesn't fail that's true but the webdriver isn't clicking properly. Could it be because of the selenium jar version I have or something like that? – user3280424 Jul 29 '14 at 16:01
  • I strongly believe it is not getting the element id or path by using findByelement. I request you to try using the button class instead in the By.xpath("").I had the similar issue ,I struggled for a while I tried various combination in the xpath.Which Selenium version are you using ? – Madhu Bose Jul 29 '14 at 16:07
  • I see the 2 button have class="btn action" .So search by inner text .find_elements_by_xpath("//*[contains(text(), 'search')]") and find_elements_by_xpath("//*[contains(text(), 'place an advert')]")..Again not tested .just giving you some inputs. – Madhu Bose Jul 29 '14 at 16:15
0

You might need to two different waits here. A. Wait for any script to finish loading B. Wait for your page to finish loading

A. If your App is using jquery it's fairly simple. Taken from here

public void WaitForAjax()
{
    while (true) // Handle timeout somewhere
    {
        var ajaxIsComplete = (bool)(driver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0");
        if (ajaxIsComplete)
            break;
        Thread.Sleep(100);
    }
}

B. wait for your page to finish loading. Taken from here

IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));

 wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));

use these two before performing any actions. Hope that solves

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73