locate the desired element using the xpath of its sibling

Is there a way to target the element following '>' using xpath without referencing its text content? Specifically, I am looking for just the element "n" in my case.

driver.find_element_by_xpath('//div/div/*[contains(text(),">")]/preceding-sibling::a')

However, this code retrieves all sibling nodes of the ">" element, including 1, 2, 3, and n.

<div >
    <div >
    <a > 1 < /a >
    <a > 2 < /a >
    <a > 3 < /a >
    <a > n < /a >
    <a > > < / a >
    < / div >
< / div >

Answer №1

If you want to target the original following sibling of a link containing the text " > ", you can use the following XPath:

//a[normalize-space()=">"]/following-sibling::a[position()=1]

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

Retrieving information from an Open Office spreadsheet using Selenium and Java

Can Open Office spreadsheet (ODS) files be utilized for reading and writing data in Selenium with Java? I have conducted a thorough search online but have not been able to find any solutions. Any assistance would be greatly appreciated. ...

Disabling Javascript in Chrome (-headless) with the help of PHP Webdriver

I am experimenting with using Chrome without JavaScript enabled. I attempted to disable JavaScript by adding the --disable-javascript command line argument. I also tried some experimental options: $options->setExperimentalOption('prefs&a ...

Encountering a glitch upon launching Selenium with chromedriver on Debian 8

I am attempting to utilize Selenium with Google Chrome. It is functioning perfectly on my personal computer, but I am encountering issues when trying to run it on my Debian 8 64-bit server. The following error message appears: root@vps:/opt/SupportBot# ja ...

Is it possible for a script utilizing selenium grid to access and manipulate files within the node VM?

Currently, I am in the process of conducting tests on a website that is expected to send data to an installed program. To streamline this process, my plan involves utilizing Selenium grid to execute the script across multiple virtual machines. This will e ...

What causes a blank page to appear in Firefox upon initial execution with Selenium?

from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() #driver.set_preference("browser.startup.homepage_override.mstone", "ignore") driver.get("https://url.aspx/") username = driver.find_element_by_name ...

The attribute "parallel" set to "none" must be one of the following values: false, methods, tests, classes, or instances

I have set up a Maven project using Selenium WebDriver and integrated TestNG. However, when I validate my Maven project, an error message is displayed stating "Attribute "parallel" with value "none" must have a value from the list "false methods tests clas ...

The outcome of the Python web crawling did not meet our expectations

After using Selenium to scrape web data, I encountered an issue where it only displayed 96 out of 346 products instead of the expected 346. Does anyone have suggestions on how to fix this problem? The crawling code is placed right after the loop for clicki ...

What is the best way to retrieve the latitude value from a table body?

I've been having trouble retrieving an integer from a table body using Python. The terminal keeps showing a 'none' type as the output, and when I remove get.attribute("value") on line 10, nothing gets printed to the terminal. from bs4 impor ...

Avoid locating the element within the website

Unable to locate the specified element The code was created using Python with Visual Studio Code from time import time import time from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By ...

Discover how to extract JSON data from a webpage even when the response is "None"

I need to retrieve data maps from their API, which are in JSON format. This is the code I have written: r = requests.get(url) if r.ok: soup = BeautifulSoup(r.content, 'lxml') soup.status_code j = json.loads(str(soup)) However, an e ...

I must retrieve the URL associated with the element labeled as "name" in Selenium using C#

After multiple attempts private string GetId(int index) { var xPath = "xpath"; var name = driver.FindElements(By.XPath(xPath)).GetAttribute("href"); return name[0].Text; } An issue ...

Systems Operated by Selenium Agents

Having just started diving into Selenium testing, I find myself pondering about browser agents. I've crafted a script that demands testing on IE8 on XP, as well as IE8 and IE9 on Windows 7. While I understand how to define the browser version, I&apos ...

Issue when attempting to run Chimp / Webdriver.io / Selenium on Fargate with failure to start Chrome

While attempting to run my test cases on Fargate using Chimp, which relies on Webdriver.io / Selenium internally, I encountered an issue. The tests execute smoothly within a docker container on my EC2 instance. However, upon uploading the container to ECS ...

Mastering the Art of Link Clicking in Email Communications

As part of my website testing with Selenium, I am facing a challenge after a user registers. They need to click on a link sent to them via email to complete the login process. While I am able to access the email, I'm uncertain about how to automate cl ...

What is the process of updating the default version of Firefox using Selenium webdriver in Ruby?

I successfully changed the Firefox version I am using to 33.1 using this code. However, I want to make the current version the default without having to add extra code to each script. path='C:\Program Files (x86)\Mozilla Firefox\firefo ...

I understand the distinction between assert and verify, but I am curious about the specific syntax of using verify in Selenium WebDriver with Java

While I understand the distinction between assert and verify, I am curious about the syntax of verify in Selenium Web Driver with Java. Can anyone provide some guidance? ...

What is the process for establishing a dependency on two distinct JavaScript files, similar to the depends-on feature found in TestNG?

I am faced with a scenario where I have two separate JS files containing test methods, namely File1 and File2. The requirement is that File2.js should only be executed if File1.js has successfully completed its execution. My current setup involves using ...

Guide on utilizing "selenium-webdriver-xpath" for extracting the text content from <td> tags?

Locate the following snippet of HTML code: <table id="supplier_list_data" cellspacing="1" cellpadding="0" class="data"> <tr class="rowLight"> <td class="extraWidthSmall"> <a href="/aems/do.list"> Cdata </a> ...

Testing your login functionality with RSpec, Capybara, and Selenium

I'm currently working on passing the login test using rspec integration testing. Although I have set up rspec and confirmed that it's functioning properly, the test is not successfully passing. Below is the code snippet: require 'spec_helpe ...

Navigating through xpath in Python Selenium?

a = driver.find_elements_by_xpath("//article[3]/div[3]/div[2]/a[*[local-name()='time']]") for links in a: print (links.text) This code snippet is part of a project I am developing for Instagram using Selenium. It aims to track the mo ...