Navigating through nested <ul> elements using Selenium and C#

Currently, I am attempting to loop through the <li> items within a <ul> object using Selenium with C#. As a newcomer to this, I am exploring ways to simplify the coding process for my testing project.

Below is a snippet of the HTML code that I am working with and I am interested in accessing the links within...

<ul class="list-menu">
    <li>
        <ul>
           <li><a class="head" href="/seramik-banyo-urunleri">Seramik Banyo &#220;r&#252;nleri</a></li>
           <li><a href="/seramik-banyo-urunleri/lavabo">Lavabo</a></li>
           <li><a href="/seramik-banyo-urunleri/klozet">Klozet</a></li>

The C# code I have written is as follows:

IList<IWebElement> results = driver.FindElements(By.XPath("//div[@class='list-menu']/li/lu/li"));

However, this code is not returning the links. What steps should I take to resolve this issue?

Answer №1

If the XPath expression contains a typo, simply change:

//div[@class='list-menu']/li/lu/li

to:

//div[@class='list-menu']/li/ul/li

Alternatively, you can opt for a more concise CSS selector approach:

driver.FindElements(By.CssSelector(".list-menu > li > ul > li"));

Here, > signifies a direct parent-child relationship.

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

Determining parent height through the positioning of children

When it comes to CSS, it's truly fascinating until you hit a roadblock and the "aha moment" seems elusive. Today, I'm struggling with adjusting the height of my parent div that contains a relatively positioned element. The issue arises from the ...

Unleashing the power of React: Integrating raw HTML <a href> tags with JavaScript

I am currently working on a small web app that mimics browsing WikiPedia by fetching raw HTML content of WikiPedia articles through its API. I then display this HTML in my app using "dangerouslySetInnerHTML". I am faced with the challenge of enabling a us ...

Displaying content on a webpage using PHP, AJAX, and HTML

Looking to update my current form setup. I have a basic Form below: <form action="" method="POST"> <input type="button" value="Generate Numbers" onclick="on_callPhp1()"/> </form> Accompanied by this javascript code: <script type="te ...

Position the outcome on the far right side

I have a question that I am revisiting with more details in hopes of finding a better solution. In the code snippet below, the output is aligned to the right of the row: <table border="1" style="width:100%"> <tr> <td align="right"> & ...

If the desktop website is zoomed in beyond 150%, it will automatically switch to mobile responsive mode

Whenever the desktop website is zoomed above 150%, it automatically switches to mobile responsive mode. Is there a way to disable this feature? You can find the website in question here: Give it a try by zooming to 150 percent and see for yourself. Appr ...

What are the steps to create a dynamic dropdown effect for navbar content using animations similar to transitions?

IMPORTANT: THE NAVIGATION BAR IS NOT USING BOOTSTRAP When I hover over the "More" button, the dropdown content appears suddenly and disappears abruptly when moving the mouse away. I would like to add a transition effect to make the dropdown content appear ...

Modify the base URL with JavaScript

Is it possible to dynamically change the href using JavaScript? I attempted to make this change with the code below in my HTML file, but unfortunately, it didn't work: <base href="/" /> <script type="text/javascript"> function setbasehr ...

Tips for eliminating horizontal scrolling in a fixed width layout

When designing a responsive website using media queries, I encountered an issue where the screen size changes to 320px and all elements are also set to 320px, but a horizontal scroll appears. Despite my efforts, I am unsure how to resolve this problem. ...

Immersive viewing experience

I am facing an issue with my full-screen bootstrap CSS website. The website appears normally, but the problem arises when Google Chrome or Internet Explorer shows the useful links bar. Is there a way to have the website display in full screen even when th ...

Switching background images for DIVs when links are rolled over

Having trouble changing the background image of a div when a user hovers over a link. Any ideas on what might be causing this issue? <style> #divToSwap { background-image: url(black.jpg); height: 150px; width: 150px; } </style> &l ...

Ways to acquire Child Generic?

Creating a BaseController class with a Generic Class TEntity. public class BaseController<TEntity> : Controller Example of usage: public class ProductController : BaseController<Product> { public ProductController(BaseService< ...

Python - experiencing challenges with accessing a website

Looking for assistance as a beginner in Python and programming. I am attempting to log in to this website using the code below, but I'm stuck on the first page. Here is the code I've been working with... import requests from bs4 import Beautifu ...

Retrieve all elements following a particular text within a web element using Selenium

We have the following HTML code snippet: <div> <img alt="Guest" > Bobby gave: <img> <img> <img> <img> and took <img> <img> </div> I am looking to extract all image el ...

Using Python Selenium, learning how to select a radio button is a key skill

I am attempting to select the "Monthly (Final)" Radio Button in the tab on the left side. Can you please click on the following link to access the information? Below is the code I have used: from selenium import webdriver import time chrome_path = r"/u ...

Utilizing Jquery and Ajax for fetching data to incorporate with Highcharts within an HTML framework

I am tasked with creating a graph that displays data over time using an ajax request, and I am seeking assistance on how to properly integrate the data with Highcharts. Below is the code snippet for reference: JSP FOR RETRIEVING DATA: <%@ page import ...

Efficiently filling multiple text boxes using Python Selenium

Currently, I am working on a Python autofill script using Selenium and Python 3.6. My main goal is to efficiently fill in text input boxes as fast as possible. At the moment, I am utilizing the following code snippet: driver.execute_script("document.getEl ...

Storing various text inputs in a MySQL database

Could anyone please assist me with fixing an issue I'm having with inserting data into a database from the form provided below? Unfortunately, I am unable to get it to work as expected. Here is the complete form: <html> <head> <m ...

Attempting to navigate the world of AJAX and PHP

My experience with AJAX is limited, but I am currently working on a project that requires a form to submit data without refreshing the page. The goal is to display the result in a modal window instead. To achieve this functionality, I understand that imple ...

The find function within $(this) is malfunctioning

I'm having issues with displaying/hiding content when clicking on a table row. Here is the simplified code snippet: HTML: <table> <tr onclick="showDetails()"> <td>Some text <br> <span class="hiddenC ...

The offspring surpasses the parent's limits and extends beyond its

I am designing a webpage layout that includes 2 navigation bars (top), a top-graphic (middle) flexbox, and a content flexbox (bottom). Within the top-graphic flexbox, I want to add a black box for text. However, I am facing issues with the box overflowing ...