isSelected (), isDisplayed не работает для меня в селене, java для флажка. Где xpath не показывает, если он отмечен или не отмечен - PullRequest
0 голосов
/ 07 февраля 2020

isSelected (), isDisplayed не работает для меня в селене, java для флажка. Где xpath не отображается, если он отмечен или не отмечен.

         <input aria-label="Resi" checked="checked" class="curam-checkbox " 
         id="__p3id" name="__p3id" title="Resi" type="checkbox" value="true">
            <label aria-hidden="true" 
           class="checkbox-touchable-area" for="__p3id" 
            title="Resi">&nbsp;</label>
         @FindBy(xpath="//label[contains(@title,'Resi')]")
         private WebElement resiCheckbox;



        public void clickResi() throws Exception {
        waitUntilTheElementIsVisible(resiCheckbox);
        if(!resiCheckbox.isSelected())
        resiCheckbox.click();
         }

Ответы [ 2 ]

0 голосов
/ 07 февраля 2020
if(!resiCheckbox.getAttribute("checked").equals("checked"))
resiCheckbox.click();

или

if(!resiCheckbox.getAttribute("value").equals("true"))
resiCheckbox.click();

Один из них должен работать.

0 голосов
/ 07 февраля 2020

Покажите пример вашего java кода, чтобы мы могли вам помочь.

Или попробуйте, как показано в примере:

driver.findElement(By.id("__p3id")).isSelected;

Кроме того. Попробуйте это:

    //Driver initialized by Chrome browser driver
    WebDriver driver = new ChromeDriver();

    //Creating wait driver. In constructor we passing WebDriver by the first parameter
    // and max time to wait in seconds by the second parameter
    WebDriverWait wait = new WebDriverWait(driver, 5);

    //Loading URL
    driver.get("Your URL");

    //Finding checkBox WebElement by id
    WebElement resiCheckbox = driver.findElement(By.id("__p3id"));

    //Waiting element to be clickable (max time to wait = 5 sec)
    wait.until(ExpectedConditions.elementToBeClickable(resiCheckbox));

    //Clicking if checkBox toggled off
    if(!resiCheckbox.isSelected())
        resiCheckbox.click();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...