2

I use Selenium Webdriver + Thucydides. When I try to use a checkbox (any state: isEnabled(), isDisplayed(), isSelected()), so an error will occur. I tried the different locators: by id, name, xpath. The checkbox is available in the page source. All other element on the page work correctly. I use DisplayedElementLocatorFactory.

My locators:

    @FindBy(id = "remember")
//  @FindBy(xpath = ".//*[@type='checkbox']")
//  @FindBy(name = "_remember_me")
    protected WebElement rememberMeCheckbox;

HTML-source of checkbox:

<label for="remember" class="remember"><div class="checker" id="uniform-remember"><span><input type="checkbox" value="1" name="_remember_me" id="remember" /></span></div>Remember me</label>

My function:

public void isLoginFormLoadedCorrectly()
{
        String pageSource = driver.getPageSource();
        System.out.println(pageSource);

        String errorMessage = "";

        if (!loginInput.isDisplayed())
            errorMessage += "Username field is not displayed or not found\r\n";
        if (!passwordInput.isDisplayed())
            errorMessage += "Password field is not displayed or not found\r\n";
        if (!submitButton.isDisplayed())
            errorMessage += "Submit button is not displayed or not found\r\n";
        if (!passwordRecoveryLink.isDisplayed())
            errorMessage += "Password recovery link is not displayed or not found\r\n";
        if (!rememberMeCheckbox.isDisplayed())
            errorMessage += "Remember me check-box is not displayed or not found\r\n";
    //    if (rememberMeCheckbox.isSelected())
    //        errorMessage += "Remember me check-box is selected\r\n";

        assertThat(errorMessage, errorMessage.equals(""), is(true));
    }

Error: net.thucydides.core.webdriver.WebdriverAssertionError: org.openqa.selenium.NoSuchElementException: Timed out after 30 seconds. Unable to locate the element Caused by: org.openqa.selenium.NoSuchElementException: Timed out after 30 seconds. Unable to locate the element Caused by: org.openqa.selenium.NoSuchElementException: Element is not usable

Pasha Rudenya
  • 21
  • 1
  • 2
  • I have set timeout, but nothing changes. There are no frames. The checkbox is in div -> form -> fieldset. – Pasha Rudenya Jun 13 '13 at 09:58
  • Which version of Thucydides are you using? The error itself doesn't look right. – Alex Okrushko Jun 14 '13 at 10:59
  • How are you using `DisplayedElementLocatorFactory`? The default factory for 0.9.125 is `SmartElementLocatorFactory` and `DisplayedElementLocatorFactory` is [not even in the list](https://github.com/thucydides-webtests/thucydides/blob/master/thucydides-core/src/main/java/net/thucydides/core/webdriver/ElementLocatorFactorySelector.java). You should be getting `IllegalArgumentException("Unsupported ElementLocatorFactory implementation: " + locatorType);` – Alex Okrushko Jun 14 '13 at 13:31
  • I have updated yesterday Thucydides from 0.9.110 to 0.9.125 and now I'm using SmartElementLocatorFactory. But the result is the same. – Pasha Rudenya Jun 14 '13 at 13:42

2 Answers2

1

I had the same error trying to click on the checkbox. I solved it by clicking element with tag <span>, not <input>.

In your example it can be found, for instance, like this (element one level higher than your checkbox):

@FindBy(xpath = ".//*[@type='checkbox']/..")
0

I cannot reproduce your issue:

@RunWith(ThucydidesRunner.class)
public class VerificationTest {

    @Managed
    public WebDriver driver;

    @ManagedPages
    public Pages pages;

    @Test
    public void testCheckbox(){
        CheckBoxPage pg = pages.get(CheckBoxPage.class);
        pg.openAt("http://www.echoecho.com/htmlforms09.htm");

        assertTrue("checkbox is displayed", pg.ckbxElement.isDisplayed());
        assertTrue("checkbox is selected", pg.ckbxElement.isSelected());    
    }
}

where

public class CheckBoxPage extends PageObject{

    @FindBy(css = ".table8 input:checked")
    public WebElement ckbxElement;

    public CheckBoxPage(WebDriver driver) {
        super(driver);
    }

}

with both FindBys: org.openqa.selenium.support.FindBy and net.thucydides.core.annotations.findby.FindBy

Since all other elements work make sure:

  1. it's not in iframe.
  2. htlm is correct
Alex Okrushko
  • 7,212
  • 6
  • 44
  • 63