1

I wish to verify which option is selected in the below code:

<div class="col-xs-12 noPadding details AdminDetails" data-value="INVITE" xpath="1">
    <div class="col-xs-8 left">Invite<br>
        <span class="permissionsDescription">Invite Users via email; Invite users already imported</span>
    </div>
    <div class="col-xs-4 right">
        <button type="button" value="1" class="accessBtn infoYes ">Yes</button>
        <button type="button" value="0" class="accessBtn infoNo active">No</button>
    </div>
</div>

I tried this way:

//Set Role Specific Privileges
        if (await driver.findElement(By.xpath("//div[@class='rightPane occupyFull']//div[3]//div[2]//button[2]")).isEnabled()) {
            console.log(`\nAll good`);
        } else {
            console.log(`\nCheck failed`);
        }

Doesn't matter what is selected on the page I always get a passing result. What is wrong with my approach? Thanks!

János
  • 133
  • 1
  • 11

2 Answers2

2

You can try with this:

await driver.findElement(By.xpath(".//button[contains(@class,'active')]").getText()
j.barrio
  • 1,006
  • 1
  • 13
  • 37
1

To print the selected option you can use the following based Locator Strategy:

await driver.findElement(By.xpath("//div[text()='Invite']//following::button[contains(@class,'active')]").getText()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352