Determine which button is active using Selenium

I am looking to determine which option is currently selected in the code snippet below:

<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 have attempted the following approach:

//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`);
        }

Despite what is actually selected on the page, my code always returns a passing result. Can anyone help identify what is incorrect with my method? Thank you!

Answer №1

If you're looking to achieve this, give it a go:

await driver.findElement(By.xpath(".//button[contains(@class,'active')]").getText()

Answer №2

If you want to output the chosen option, you can utilize this based Locator Strategy:

await driver.findElement(By.xpath("//div[text()='Invite']//following::button[contains(@class,'active')]").getText()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Conducting parallel TestNG selenium tests with dataprovider to analyze driver behavior in action

I am looking to run Selenium tests in TestNG in parallel using the @dataprovider feature. My goal is to have tests running in parallel by method (one test = one method) instead of simple suite parallelism by browser. I have come across information stating ...

Utilizing Twitter Bootstrap to populate form fields from a dropdown selection

I am currently using twitter bootstrap for my front end web development project. I have successfully implemented a text field with a dropdown menu right next to it: <div class="input-group"> <input type="text" class="form-control" name="ope ...

Waves emanating from the heart of rings

I'm experimenting with creating a ripple effect using Anime.js on an array of dots forming circles. Despite trying various methods, I can't seem to achieve the desired result. Does anyone have any suggestions on how I can make it work? Here&apos ...

Bootstrap tab toggling with checkbox

I'm attempting to create tabs with the ability to include checkboxes, but when using data-toggle="tabs", the checkbox functionality seems to be disabled. Here is the link to my fiddle. Is there a solution to make the checkbox work within the tab tog ...

Determine the amount of interconnected nodes listed in a csv file depicting their relationships

I have a sizable CSV document formatted as follows: ServerID|AppID 01 | 01 01 | 02 02 | 02 02 | 03 02 | 04 03 | 04 The information from this file is being used in a d3 force layout, demonstrated in this example. The cr ...

Have you ever wondered why req.body returns as undefined when using body parser?

Every time I attempt to make a post request, I keep receiving an error message stating that req.body is returning as undefined. Below is the content of my server.js file: import express from 'express'; import bodyParser from 'body-parser&ap ...

Achieve automated zooming out using highcharts-ng through code

Currently, I am using Highcharts-ng as seen on https://github.com/pablojim/highcharts-ng Upon inspecting the source code, I have noticed some interesting functionalities in the directive utilizing scope.$on which I can leverage for broadcasting. One examp ...

Utilizing jQuery's AJAX method for Access-Control-Allow-Origin

Here's the code snippet I'm working with: $.ajax({ url: url, headers: { 'Access-Control-Allow-Origin': '*' }, crossDomain: true, success: function () { alert('it works') }, erro ...

Displaying specific choices depending on the previous selection made

I am facing an issue in Laravel where I have two selection options, and one depends on the other. Despite multiple attempts, I haven't been able to resolve it. The database structure is as follows: companies id title channels id company_id title I ...

Which event in the listbox should I trigger to adjust the scroll position?

My webpage includes a listbox inside an update panel. I've managed to capture the scroll position, but now I'm facing difficulty in identifying the right javascript event to call my function for setting the scroll position after the update panel ...

Exploring the Depths with a Javascript Canvas Deep Zoom Library

I am faced with the task of creating a detailed zoom mosaic using an HTML5 Canvas Element, consisting of thousands of roughly 512x512 images. However, I am striving to minimize reinventing the wheel in the process. Instead of merging numerous large images ...

What kind of performance can be expected when storing a Uint8Array in IndexedDB?

Is it more storage-efficient to store a uint8array or an arrayBuffer with the same data in indexedDB? That's my question. ...

AngularJS- issue with button visibility on 'toolbar' widget

In my angularJS application, there is a page with multiple widgets displayed. When a user clicks on the 'Settings' button on the page (separate from the widgets), a toolbar for each widget appears showing different buttons depending on the widget ...

Can you show me how to design a website with an embedded browsing window and a customized right-click menu?

I am looking to develop a website that includes a window or frame where users can browse other websites. Additionally, I am interested in implementing a custom right-click menu within this browsing window. While I know that using iframes can help with th ...

Executing Java method via JavaScript by simply clicking a button

I am currently facing a challenge in finding a way to invoke a Java method from JavaScript and pass user input variables into the method call. The main issue I have encountered is that JavaScript seems to interpret/resolve the Java method during page load. ...

Nextjs is not updating the Redux api state

I am working on a vehicle form component where users can select the year, make, and model of their vehicle. When a user selects the year, I trigger a Redux action to fetch all makes for that specific year. Subsequently, when the user selects a make, anothe ...

Using jQuery to show and hide elements on a webpage

One issue I'm facing is changing the content on a page depending on the clicked link. The problem arises when the displayed content for one link persists even after clicking another link, despite setting it to not display when another link is clicked. ...

Automatically redirect to the destination by clicking on the href link

import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys #from webdriver_manager.chrome import ChromeDriverManager Base_Li ...

What is the best way to adjust the value of largePageDataBytes in Next.js?

I am looking to modify the largePageDataBytes setting, despite knowing it may impact performance. I made an attempt in next.config.js with the following code: /** * @type {import('next').NextConfig} */ const nextConfig = { /* config options h ...

Conceal flex items when there is inadequate space available

I need help with customizing my JIRA timeline chart to show information about epics in progress. When an epic spans multiple releases, there is enough space on the timeline bar to display all relevant details. However, if an epic only spans one release, th ...