Issue with clicking the OK button in Selenium WebDriver using Java due to the presence of a span tag within the button tag

This is the HTML code snippet that I am working with:

<div id="sieb-ui-popup-mvg-selected" class="AppletStylePopup">
    <form onsubmit="return false;" action="/ecom_enu/start.swe" method="post" name="SWEForm4_0">
        <div class="siebui-popup-btm siebui-mvg-btn-modifier">
            <span class="siebui-popup-button">
                <button id="s_4_1_79_0_Ctrl" class="siebui-ctrl-btn siebui-icon-closeapplet s_4_1_79_0 appletButton" aria-label="Responsibilities:OK" title="Responsibilities:OK" tabindex="0" data-display="OK" name="s_4_1_79_0" type="button">
                    <span>OK</span>
                </button>
            </span>
        </div>
    </form>
</div>

I am trying to click on the OK button, but so far my attempts have not been successful. Here are some methods I have tried:

driver.findElement(By.cssSelector(".siebui-ctrl-btn.siebui-icon-closeapplet.appletButton")).click();

Another attempt I made:

driver.findElement(By.xpath(".//*button[@title='Responsibilities:OK']/span[contains(text(),'OK]')).click();

I also tried this approach:

driver.findElement(By.xpath("//button[contains(span/text(), 'OK')]")).click();

Lastly, I attempted the following method which resulted in a Timeout error:

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("iframe-applicationname_ModalDialog_0"));
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//span[contains(text(), 'OK')]")));
el.click();
driver.switchTo().defaultContent();

Answer №1

If you're struggling to find the right xpath for your web elements, consider utilizing the firebug and firepath extensions on Firefox. These tools can greatly assist in identifying the correct xpath solution. If you're unsure how to use firebug to capture xpath, check out this helpful guide here. Make sure to install firebug and firepath addons on your Firefox browser before attempting to capture xpath.

Answer №2

If you’re looking for a solution, consider the following steps:

Start by obtaining the root element and storing it as a WebElement object. Next, locate the Ok button element and click on it.

WebElement elem = driver.findElement(By.cssSelector("#sieb-ui-popup-mvg-selected > form > div"));
makeWait(5);  //Adjust the wait time as needed       
elem.findElement(By.cssSelector("button[type='button']")).click();

Create a separate method, either local or global, to introduce a brief delay

/*
 * Introduce a brief delay in execution
 */
public void makeWait(int waitForSecond)
{
    try {
        Thread.currentThread().sleep(1000 * waitForSecond);
    } catch (InterruptedException ie) {
        System.out.println(ie.getMessage());
    }
}

You have the option to omit the makeWait() function if it’s not required. It could potentially be beneficial in certain scenarios.

Answer №3

Make sure to reference the code provided below for potential success:

driver.findElement(By.xpath(".//*[contains(@class,'siebui-popup')]//span[text()='OK']")).click();

Consider utilizing Firepath on Mozilla Firefox to experiment with various CSS and XPATH combinations for identifying elements accurately. This tool will assist in determining the appropriate selectors needed.

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

Look up the attribute in the parent node and retrieve the value of the child node's attribute

Simplified Version: Find attribute in parent node and retrieve attribute values from child nodes. Detailed Version: Within an XML file, I have the following snippet: <include template="directory/file.xml"> <param name="permission" va ...

What is the best method to create Promise API synchronously?

When it comes to testing with NodeJS, I rely on selenium-webdriver. My goal is to streamline the selenium-webdriver API by making it synchronous, which will result in more concise tests. The method getTitle() is used to retrieve the title of the current p ...

The error message "NoSuchSessionError: invalid session id" pops up in Selenium, despite the fact that the application is running smoothly

Scenario and Background: I have recently developed a script to access an external website and extract specific data. The script's purpose is to retrieve grades of students and convert them into usable data for plotting. In order to streamline the dat ...

Tips for interacting with a custom web component using Selenium WebDriver

As a newcomer to writing selenium tests, I am attempting to create an automated test for a carousel feature on our homepage. The objective is to click on one of the carousel navigation buttons and then confirm that a specific inline style has been applied ...

Single Linked List - retrieve and insert functions

Today I'm tackling the challenge of implementing an SLList class by completing operations such as: get(i), set(i, x), add(i, x), and remove(i), all designed to run in O(1 + i) time. The areas where I'm encountering issues in my program are part ...

Protractor unexpectedly giving back a promise instead of the expected attribute value

I'm facing a challenge where I am attempting to extract the value of an HTML attribute and store it in a variable named url_extension. However, instead of getting the desired value, I keep receiving a Promise object. Below is my code snippet: (Please ...

Executing Nightwatch.js Upload Command

Looking to develop a nightwatch action that involves uploading files to a specific upload form. Can an action like this be created within the nightwatch framework? Nightwatch is linked to a nodejs app and operates through a selenium webdriver. ...

Why am I getting the error "Chai assert.isBoolean is not defined as a function"?

Snippet of code: driver.wait(function(){ return driver.isElementPresent(webdriver.By.className(errElement)); }, 3000, 'Element' + errElement + ' is not found').then(function(binaryVariable){ assert.isTrue(binaryVariable, &apos ...

Extracting elements using Node.js and Selenium

I'm currently experimenting with Selenium and nodeJS for the first time. I'm trying to parse an HTML page and am running into issues when attempting to perform a deeper search using XPATH on returned elements. Below is my code: async function par ...

The situation arose when Webpack unexpectedly terminated before completion

Currently, I'm facing an issue with my project that I've been developing using Vaadin 14.4.10 and Node.js 14.16.1 without any hassle until now. The only recent change I made was updating the Vaadin version to 23.3.6 while working in a local branc ...

"Exploring the dynamic capabilities of Node.JS and Java Publisher/Subscriber

I am working on developing an application where communication will be facilitated through a node.js server. This node server is responsible for receiving messages from other peers. Here is the code snippet for my node.js: var zmq = require('zmq&apos ...

Connecting to WS Protocol in Android devicesorHow to

After developing a Node.js server for my client that utilizes WebSocket technology, I successfully tested it using JavaScript. Now, my goal is to integrate this connection into my application. The server communicates through the WS protocol (ws://) and sen ...

Steps for uploading a file with WebdriverIO

Currently, I am in the process of converting this Ruby code using the selenium-webdriver gem into Node.js with WebdriverIO: @webdriver.navigate.to "https://imgur.com/upload" element = @webdriver.find_element(:id, 'global-files-button') element.s ...

Using JavaScript and the Firefox browser, learn how to easily highlight an element with Selenium-WebDriver

I am struggling with creating a valid function to highlight specific elements on a webpage. As a beginner in coding, I suspect that the issue may either be related to my environment setup or a lack of knowledge about JavaScript/Selenium features. I am wri ...

Developing single-page application frontends without utilizing node or npm

As a backend java developer with experience in spring boot, I am now exploring the world of single page applications. One aspect that appeals to me about SPA frameworks, particularly Vue, is things like model-binding and the use of components and template ...

Building a Personalized Docker Image for Node.js and Selenium-Webdriver: Step-by-Step Guide

Having trouble getting my automation project to run in Jenkins. Issues with Docker images downloaded from the Internet and Linux agent compatibility with my Windows environment. I manually downloaded Google Chrome/Chromedriver in the build, but still can& ...

Why does Request-Body(req.body) display a value while Request-QueryParams(req.queryParams) returns null?

Using vuejs-axios, I successfully transferred client-side data to the server-side using Java with SparkJAVA Framework to manage the request-response cycle. The following code snippets demonstrate how Form-Data is posted from vuejs to java. const formData ...

Exploring the potential of button click events in Discord.js v13

I'm attempting to create a button click event in discord.js version 13, but for some reason it's not functioning properly. Here's the code I've written: client.on('interactionCreate', async button => { if(button.CustomI ...

Converting hexadecimal string to a double value in Java

Currently, I am working on decoding the value of the "Well-known Binary" format using Java. The Node script below accomplishes this task: Buffer.from('A4C0A7DEBFC657C0', 'hex').readDoubleLE() // returns -95.1054608 I am struggling to f ...

The DevToolsActivePort file for Selenium on Heroku cannot be found

I'm currently in the process of deploying a node and selenium application to Heroku. Here is a snippet of my code: let options = new Options(); options.setChromeBinaryPath(process.env.GOOGLE_CHROME_BIN); options.addArguments("headless"); options.addAr ...