Can I combine Following and preceding in Selenium for testing?

https://i.stack.imgur.com/tDnqb.pngAs I explore the content on this page https://en.wikipedia.org/wiki/Trinity_Seven#Episode_list here's what I have encountered:

//*[text()='Reception']//preceding::th[contains(@id, 'ep')]//following::I 

However, it seems to only register the elements that follow.

The default firepath selector is:

.//*[@id='mw-content-text']/div/table[5]/tbody/tr/td[1]/I
, but such selectors are prone to breaking frequently. I'm wondering if there might be a better approach to achieve this, hence exploring this method.

Thank you in advance! :) - It appears to be fetching data under the table, which is not my intended result :S

Answer №1

Utilize the following XPath to identify necessary elements:

//th[contains(@id, 'ep')]/following::I[./following::*[text()='Reception']]

Answer №2

This seems simpler

//tr[contains(@class, 'vevent')]//i

Keep it simple. Just make sure each row has an I tag inside. Locate the row with tr[contains(@class, 'vevent')] and find its I

An alternative approach is to confirm if a specific element is within the parent element before locating a different element. This can be done using this format: //element[./specific]//child , so in this scenario:

//tr[contains(@class, 'vevent')][./th[contains(@id,'ep')]]//i

This finds the I tag inside the row that contains @id,'ep' in the header

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

Automating downloads using chromedriver and selenium: A step-by-step guide

I am encountering an issue with my Node.js file which is as follows: var webdriver = require('selenium-webdriver'); var chrome = require('selenium-webdriver/chrome'); var driver = new webdriver.Builder() .withCapabilities(webdriver.C ...

C# error: Failed to load DLL 'AutoItX3.dll': The module specified could not be located. (Exception from HRESULT: 0x8007007E)

The DLL can be found within the 'References' section. I have successfully executed the test using 'Test Explorer'. Issue: However, when I run the same test using mstest commands, I encounter the following error: Error: Unable to load ...

Switch _ Click on it is required in python using selenium

I'm attempting to create an xpath for a toggle switch. Essentially, I need to click on the following element in order to toggle it: Actual HTML code <label class="" for="toggleResume" data-e2e="toggleResume"><s ...

In some cases, there are blank values in a list of web elements. How can we implement a wait in Selenium to ensure each value of the web element appears in the list of web elements?

ArrayList<String> corousalItems= new ArrayList<>(); List<WebElement> listText= driver.findElements(By.cssSelector("CorousalList")); for (WebElement list : listText) { String text=list.getText(); corousalItems.add(text); } System.ou ...

Automating Vaadin components using Selenium WebDriver

Currently, I am utilizing Selenium Java WebDriver to automate a web application that is based on Vaadin. Upon navigating to a particular page and clicking on a button, it triggers the opening of another smaller window which doesn't quite resemble a ty ...

Having difficulty navigating to the subsequent page link

I have created a Python script using Selenium to extract data from a JavaScript-enabled webpage. To navigate to the next page, I need to perform three actions: fill in two search boxes and click the search button. The issue arises when the script fails to ...

Steps for updating the ChromeDriver binary file on Ubuntu

I've been using Python / Selenium / Chrome / ChromeDriver for various tasks like testing and scraping. Recently, I've been trying to change the cdc_ string to something else in a file. However, even after replacing it with cat_ in vim, nothing se ...

What is the method for triggering the Enter key event in Selenium Webdriver with Ruby bindings after entering text into a text box?

Can we input text and press the enter key simultaneously, instead of using send_keys:return separately for each action? Thanks, Abhishek ...

Scraping with Selenium is unable to detect HTML elements that are loaded dynamically

Currently, I am utilizing Scrapy in conjunction with Selenium for the purpose of scraping content from the following page: On this page, there exists a table located under the div labeled as .game_info_panel_widget, where it appears that the first row whi ...

Guide to easily accepting all cookies using Webdriver and Selenium when conducting a flight search on Kayak website

Looking to extract flight data using Selenium WebDriver. Kayak presents a cookie notification right off the bat: I need to select the "Accept all" button. HTML <button role="button" class="RxNS RxNS-mod-stretch RxNS-mod-variant-outline ...

Avoiding the use of thread.sleep in dynamically populated lookup field options in Selenium

I am currently working with a dynamic lookup Salesforce component on my webpage. https://i.stack.imgur.com/lxr3q.png <input lightning-basecombobox_basecombobox="" id="input-19" type="text" role="textbox" autocomp ...

Extracting JavaScript OnClick button using Selenium

I'm having trouble extracting the email address from the following URL: https://www.iolproperty.co.za/view-property.jsp?PID=2000026825 that is only visible after clicking on the "Show email address" button. However, every time I attempt to click and r ...

Using Java Selenium WebDriver, you can choose an option from a drop-down menu based on its value,

I am encountering an issue when trying to select from a dropdown menu using SelectByValue while ignoring case sensitivity. For example: Japan Albania The value is "Japan," but the input I have may be in lowercase such as "j ...

Using Selenium to interact with li elements by clicking on them

I am currently developing a web automation tool with Selenium, and I am facing an issue while trying to click on a specific li item within a ul element. Although I have successfully looped through the ul elements and displayed all the li items, I am unabl ...

I'm currently experimenting with JAVA and Selenium to automate testing for a WebApplication

Is it possible for someone to choose an item from the drop-down list called "Furniture Type"? I have managed to click on the furniture type using the following code: driver.findElement(By.xpath("(//select)[1]")).click(); However, I am struggling to actua ...

Once an email address is entered, kindly instruct the driver to press the tab key twice for navigation

Adding a user to a website involves entering an email address first, which is then checked against the server's list of users. However, the issue arises when the email validation doesn't occur until clicking outside the input box or pressing tab ...

Python's Selenium WebDriver seems to be malfunctioning when using `driver.find_element(By.XPATH, '')` syntax

Hoping to retrieve the Full Name "Aamer Jamal" using Selenium WebDriver from the provided URL above. However, encountering an issue where a NoSuchElementException is thrown. `Check out the code snippet below: from selenium import webdriver from selenium.we ...

Guide to selecting individual apartments on Airbnb with selenium

My latest project involves creating a scraper for Airbnb. The goal is to navigate through each apartment, take a screenshot, move to the next one, and repeat the process. However, I'm encountering an issue where the scraper clicks on the first apartm ...

executing automated tests with Selenium in headless mode using Jenkins on a Windows environment

I specifically designed my application to be compatible with Internet Explorer only, which is why it may not function properly in Phantom JS or HTML Unit Driver. Is there a way to run it in Jenkins in headless mode on Windows? ...

An error in the Generic Device Interface Plus (GDI+) framework occurred while attempting to capture a

An unexpected GDI+ error occurred while trying to capture a screenshot. Despite having write access to the folder, I am puzzled as to why this error is happening. Below is the code that is causing the issue: driver = new FirefoxDriver(); string ba ...