Ways to choose a particular radio button from a set of similar radio buttons using Selenium WebDriver

Seeking assistance with automating the booking process on an airline website. On the second page of the booking process ('Select Flights'), there are numerous radio buttons that appear very similar to each other. How can I ensure that I select the specific radio button I want to click?

I have attempted using xpath to identify the radio button without success. Here is the HTML code for the radio button: View screenshot from booking.airasia.com

Your guidance and advice would be greatly appreciated. Thank you.

Answer №1

Primary element https://i.stack.imgur.com/CvjRf.jpg

Secondary Element https://i.stack.imgur.com/5BuLq.jpg

While it may seem like you are retrieving identical elements with the given xpath, exploring their surroundings such as siblings and parents can lead to different outcomes. The xpath I utilized pinpointed the specific elements you were after, as shown above.

//div[@class='iradio_square-green']/input[@id='trip_0_date_0_flight_0_fare_0']/following-sibling::ins

To apply this to other radio buttons, simply adjust the flight number.

I hope this information proves useful to you! :)

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

A comparison between XPath and JQuery locators when using Selenium

After discovering that individuals utilize JQuery element-locators in Selenium, I am intrigued by the concept. I would like to inquire about the advantages of using JQuery selectors over XPath selectors. Are they considered more adaptable or quick, parti ...

Exception encountered for Internet Explorer when attempting to launch from WebDriver: 405 Method Not Allowed

After trying to launch IE from Webdriver and clicking on save, I encountered a "405 Method not allowed" exception. However, when I manually launched IE and clicked on save, it worked fine. I'm perplexed by this issue. Any ideas as to why it might be ...

Streamline your Salesforce application by automating drop down selections with XPath using Selenium WebDriver

https://i.stack.imgur.com/Eg9jc.pngAn application has been developed in Salesforce with a dropdown box containing items built using the <li> tag. However, I am unsure how to select a specific item from this design. <div id="Department__cformContr ...

I'm curious if it is possible to retrieve the dates of actions on websites using Selenium with Python

Is there a way to retrieve the date of data, like the date of comments, using HTML codes? I need assistance on how to achieve this through selenium in Python. Can Jquery be used as a solution? ...