Navigating to an element within a span tag: Selenium

Hey there! I'm currently working on automating a task in Selenium WebDriver using Java, and I need to figure out how to click on a specific button that has the text "€11" on it.

This button is embedded within this structure, and there happens to be another button on the same page with identical code but a different price:

<button type="button" class="bui-button bui-spacer--medium bui-button--primary bui-button--wide">
<span class="bui-button__text">€11</span>
</button>

If you have any advice or suggestions on how I can achieve this, I would greatly appreciate your help :)

Here's the full CSS for reference

Answer №1

Here are some suggestions that might be useful

Vanilla JS:

document.querySelector("button.btn-primary").click()

jQuery:

$("body > button.btn-primary > span").click()

Selenium (Python):

driver.find_element(By.cssSelector("button[class='btn btn-success']").click()

I hope these solutions work for you!

Answer №2

Here are a couple of options you can consider:

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

To click the first button:

driver.findElement(By.xpath("(//span[@class='bui-button__text'])[1]")).click();

For clicking the second button:

driver.findElement(By.xpath("(//span[@class='bui-button__text'])[2]")).click();

Please remember to use waits if there are any delays in loading the amount.

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

Chrome does not support gradient, while Firefox does

When I attempt to utilize the webkit gradient tag specifically for Chrome, it fails to function altogether. On the other hand, when tested on Firefox using background:-moz-linear-gradient(#000, #888);, it operates smoothly. Despite this, applying backgrou ...

MVC Template with a Defective BootStrap

Struggling with creating an MVC master template along with sub-pages using Bootstrap. Sadly, I seem to have messed it up and can't quite figure out where the problem lies. You can check out my test website at Do you see how the different sections a ...

Click on the shadowed div element to interact: inset

Is there a way to make elements clickable/focusable within a div that has an inset shadow, like the .calendar in this example? Check out this code snippet: https://jsfiddle.net/axel50397/846ostv5/9/ <div class="calendar"> <div class="card-dec ...

Cycling through choices in a dropdown menu

I am working on a project where I need to iterate through the values displayed in a dropdown menu on an HTML web page. The values are alphanumeric, and I have written the code below to read all the values correctly. However, I am encountering an issue wher ...

Discover the secrets to replicating the mesmerizing horizontal scrolling menu akin to the

What is the most effective way to create a horizontal menu similar to the innovative Google picture menu? Could someone kindly share their knowledge and provide the code for achieving the same outcome? ...

Having trouble with the for loop when trying to locate elements by XPATH using driver.find_element_by_xpath

I am only receiving the first row item for the first column as output. Can someone please identify the issue and explain why the for loops in this code are not functioning correctly? from selenium import webdriver url="https://www.up-rera.in/frm_san ...

Angular 7 and Spring 5 are being hindered by CORS restrictions

I'm currently working on a project that involves Spring 5 with Spring Security and Angular 7. I am facing an issue while trying to connect the frontend, receiving the following error message. It's worth mentioning that the backend and frontend pr ...

Text Fade-in Animation with CSS 3

Could someone assist me in creating an animation similar to a marquee using CSS "animation" and "keyframes"? I attempted to move text from top to bottom, but encountered an issue where the text would only restart its movement from the top once it reached ...

Buttons are not aligned with the rest of the row's height

I'm currently working on designing an upload layout that consists of a container with a row inside. Within the row, there are two buttons (each containing input elements) and one h3. For some reason, I am having difficulty getting them to align at the ...

Changing innerHTML with HTML generated by a PHP function? (utilizing xajax)

I have managed to successfully update the content inside a DIV using xajax when clicking a link. However, I noticed that it only works when I directly assign HTML within the function itself, not when calling it from another function. Allow me to demonstra ...

First example of combining Spring, Thymeleaf, and AngularJs: no issues, yet functionality is not operational

I am currently working on a project using Spring MVC 4.2.6 along with webjars libraries and the Thymeleaf framework. I have implemented a simple example in a template called 'test.html' mapped to '/test' in the controller: <!DOCTYPE ...

What is the best way to choose the right value based on parameters?

I am currently working on a solution using protractor where I have several options to consider. Specifically, I need to test timeslots between 1600 and 1900, along with an else statement. For instance, if the 1600 timeslot is selected, then the code shoul ...

Adjust the input width dynamically in Angular

Looking to dynamically adjust the width of an input field and ensure that the suffix "meters (m)" sticks close to the entered number. Additionally, I want to pass a specific value to the input using `value="something"`, which then should expand the input w ...

Is there a way to create a footer that seamlessly integrates with the borders of a website?

I've been struggling to design a footer for my class website project. The problem is that the footer either overlaps the borders of the site or the text inside the footer goes under the border. I've tested several different footers, but none seem ...

The declaration of org.openqa.selenium.firefox.FirefoxDriver cannot be found

I'm facing an issue where Eclipse is not recognizing the downloaded libraries when I try to import a class. I attempted to update my Maven project through Maven-> Update Project but that did not resolve the issue. I also tried removing all dependen ...

Exploring creative methods for incorporating images in checkboxes with CSS or potentially JavaScript

Although it may seem like a basic question, I have never encountered this particular task before. My designer is requesting something similar to this design for checkboxes (positioned on the left side with grey for checked boxes and white for unchecked). ...

Creating an AngularJS directive specifically for a certain <div> tag

Recently, I began learning angularjs and came across a script to change the font size. However, this script ended up changing all <p> tags on the entire webpage. Is there a way to modify the font size of <p> tags only within the <div class=" ...

The method `steps` cannot be found for the object of type `Cucumber::Ast::OutlineTable::ExampleRow`. This results in a NoMethodError

My cucumber feature file is structured with a scenario outline as seen below: Scenario Outline: And the user looks for the item "<item>" Then the homepage should be active And the user selects "<type>" type(s) Examples: | item | type ...

Having trouble finding the element with a xpath that includes numerous 'div' elements

Currently, I am on the hunt for an element within a chatbot that is a simple message, not a hyperlink. My initial attempt involved capturing the XPath using 'inspect' and employing the following code: driver.find_element_by_xpath("//[@id=&ap ...

The login button remains disabled in Selenium IDE despite entering login inputs

I'm currently working on automating the login process for a website. On the login screen, there are fields for username, password, and a login button. The login button is only enabled when both the username and password are entered. While recording w ...