Tips for obtaining the XPath for an unordered list and a span element

My goal is to find the xpath that will select the seat "12A" from a webpage containing a list of seats. Here's the source code:

<div class="seats" style="top: 48px;">
  <ul class="row_12 leftOfAisle">
    <li><a class="" data-row="12" data-seat="A" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12A</span></a></li>
    <li><a class="" data-row="12" data-seat="B" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12B</span></a></li>
    <li><a class="" data-row="12" data-seat="C" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12C</span></a></li>
  </ul>
</div>

After trying out various options, I ended up with this xpath which did not work as expected:

"//*[@class='seats']/ul[@class='row_12 leftOf`Aisle']/li[1]/a"

Answer №1

Try using the Xpath below:

//div[@class='seats']/ul[@class='row_12 leftOfAisle']//span[contains(.,'12A')]

Here is the code snippet for the same functionality:

List<WebElement> allSeats = driver.findElements(By.xpath("//div[@class='seats']/ul[@class='row_12 leftOfAisle']//span"));
for(WebElement seat: allSeats){

        System.out.println(seat.getText());
        seat.click(); // Click each element if 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

Scrolling with Jquery window.scrollTo results in the page becoming unresponsive

I'm currently revamping a website that features a header with 100% screen height, but I need it to shrink down to 0px when a user starts scrolling. The issue I'm facing is that once the header shrinks to 0px, the page content ends up slightly abo ...

Every day, utilize C# to retrieve a file from a website

I have searched through many posts on this website related to my topic, but none of them have provided a satisfactory answer to my specific question. Basically, I am looking for a solution that will enable me to download a file from a website while adheri ...

Struggling to Locate Elements by Xpath or Text Using Selenium Webdriverjs

After finding a few more issues to address, I am back to where I left off yesterday. My challenge now is to locate these elements using only text. Eventually, all will be updated to utilize ids. When I analyze the element in FirePath, the xpath is quite m ...

Swap two frames effortlessly with just a single click!

Is there a way to effortlessly change the contents of two frames with just one click? With a single click, I'd like to modify both "framename" and "framename2" by setting their href attribute to 'qwerty' and 'qwerty2' respectively ...

JavaScript PIP video feature

Currently, I am utilizing the requestPictureInPicture function to display the HTML video element in a popup window. However, I have encountered an issue where the size is restricted to approximately 920 x 540 when in Picture-in-Picture mode. I am wonderin ...

Having trouble understanding the differences between Bootstrap 4's .list-inline class and .list-inline-item class?

I am currently utilizing Bootstrap 4 within Wordpress. Strangely, I am facing an issue where I am unable to have list items appear inline (horizontally) solely by using the class .list-inline on the list itself, as shown below: <ul id="dances" class="l ...

The <h:outputStylesheet> tag fails to display any content on the HTML page

I am having trouble getting my CSS sheet to load while using JSF2 and PrimeFaces. The CSS file is located at WebContent/resources/css/style.css Here is the xhtml code: <h:head></h:head> <h:body> <h:outputStylesheet name="css/styles. ...

Using React Material UI icon within an auto complete feature

https://i.stack.imgur.com/W3CmF.png I am struggling to incorporate the target icon into the autoComplete component. After reviewing the documentation, I have been unable to find a solution. In TextInput, a similar outcome can be achieved by implementing ...

Having trouble creating the right XPath for the top movies on IMDB using Selenium

I'm having trouble clicking on the Top Rated Movies section within "Movies, TV & Showtimes" on IMDB. I'm unsure of how to write the correct xpath for it and can't seem to figure out how to click on it. Below is the snippet of code I am usin ...

Is there a way to enhance the height of Bootstrap combobox items? Can this be achieved?

Is it possible to improve the height of Bootstrap combobox item? How can I achieve that? 1 2 3 4 ...

What steps should I take to ensure that flex aligns the inner-divs on the same row?

I have observed that flex can easily align input tags, regular text, and other elements perfectly on a single line with the flex-direction:row; property. However, this alignment seems to get disrupted when one of the elements is a div. For example: <ht ...

Revamping the login interface for enhanced user

Whenever I attempt to login by clicking the login button, there seems to be an issue as it does not redirect me to any other page. Instead, I am left on the same page where I initially clicked the button. The intended behavior is for users to be redirected ...

What is the best way to display input data (with names and values) in a textarea field

I'm currently working on a project that requires the value of a textarea to be updated whenever one of the input values in the same form is changed. Here is the HTML code: <form id="form" action="" method=""> <textarea readonly class="overv ...

What is the best way to position a div to float or hover from the bottom after it has been

I am working on creating a menu where clicking it will reveal a submenu at the bottom, but I'm encountering an issue. Currently, in my code, the submenu is appearing from right to left before moving down. Here is my code: <meta name="viewport" co ...

Inconsistencies with Handlebars adding forward slashes "/" to page addresses are causing confusion among users

In my project, I have 10 unique .handlebars files that are being called using express GET methods as shown below: app.get('/pagename1', function(req, res, next) { res.render('page1'); }); app.get('/pagename2', function(req ...

Reverse the orientation of the SVG image, for instance, the graph

I've been experimenting with creating a bar graph using SVG, but I'm struggling to understand how it works. I tried rotating an existing graph upside down, but there seems to be a small offset. You can view the corresponding jsfiddle here - http: ...

Mastering CSS Sprites: A Guide to Aligning Sprite Buttons at the Bottom

In my web app, I have a bottom navigation bar with 9 buttons, each represented by a Sprite Image having 3 different states. The challenge I'm facing is aligning all the images at the bottom of the nav bar or div. The icons vary slightly in size, and ...

Using Firebase with the async pipe in Angular 5

I am struggling to implement async pipe in Angular firebase and encountering an error that I cannot resolve: ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' Utilizing the Firebase NoSQL database: { "bos ...

Incorrect implementation of Bootstrap CSS in Jade template

Currently, I am leveraging Express to construct a website. However, there seems to be an issue with my jade template not displaying the bootstrap grid system accurately. Despite double-checking that my app path is correctly set through app.use(express.stat ...

Unable to identify an element using Selenium that has a matching CSS selector with another element on pagespeed.web.dev

Currently, I am utilizing Python with Selenium WebDriver to fetch the value of "First Contentful Paint" for Desktop on . This particular value is only visible after analyzing a website. However, both the Mobile and Desktop instances share the same CSS Sele ...