Locate the grandchild of an element by utilizing the parent element

I'm working with HTML code that looks like this

<div class="A"> 
   <div class="B">
       <div class="c">
        </div>
   </div>
</div>

If I use A.element(by.css(.c)), will I be able to target the div with the class "c"?

When using ParentElement.Element(some locator), does it only search for direct descendants of the parent element or also look in grand children?

If A.element(by.css(.c)) is not the correct approach, what is the right way to target grandchildren of a parent element?

Answer №1

When you have a div with a unique class, using element(by.css(".c")); will locate that specific div. There are various other locators you can utilize as well. Just keep in mind that this method is specifically for finding the element with the class "c", not its grandchildren.
If your goal is to find a grandchild element without a class attribute, xpath can come in handy:

element(by.xpath("div>div>div"));
However, it's generally recommended to use a unique locator like an ID or class for more reliable results.

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

Guide to interacting with the Li element using JavaScript in Selenium

Is there a way to click on the item inside the li element using a Selenium script with JavaScript? I've tried different methods like By.cssSelector or by css, but I keep getting an ElementClickInterceptedError: element click intercepted:Other element ...

Encountering problem "Class not found in classpath" while using selenium

Currently, I am studying Selenium and while attempting to run the program below, I encountered an error stating "Cannot find class in classpath:practiseAutomation". The code is as follows: public class practiseAutomation { public WebDriver driver; String ...

Python script designed to execute all test scripts stored within a specified directory

I'm working on developing a script to automate running all of my testing files stored in a directory. project folder Test_one.py Test_two.py Test_three.py ... Test_ten.py My goal is to create a file named "run_test.py" that can effectively carry out ...

I am seeking assistance with locating a button using Selenium Firefox Webdriver and require guidance on the code necessary to click the

Seeking assistance with Selenium to click on the Income Statement button located at . Can anyone identify the button name and review the code for accuracy in implementing it? Grateful for any guidance. Thank you! url = 'http://www.tradingview.com/scre ...

Encountering the org.openqa.selenium.UnsupportedCommandException while attempting to use the mouseMoveTo

Currently, I am working with Selenium 3.5.3 and a standalone selenium box setup. I have been attempting to hover over an element using the code below: RemoteWebDriver driver = null; DesiredCapabilities dc = new DesiredCapabilities(); dc.setCapability("bro ...

"Exploring the use of Selenium Webdriver to extract data based on class name

<li class='example'> content1 </li> <li class='example'> content2 </li> <li class='example'> content3 </li> Within this HTML snippet, I am aiming to gather all the text within elements that ...

Why does every element appear identical in selenium?

When attempting to convert my Steam game-hours into a pandas dataframe, I am encountering an issue where all the games and hours appear identical. Is there a mistake in my code causing this problem, and if so, how can it be resolved? Output: title ...

What is the method to initiate a fresh instance of Selenium Webdiver for every thread in a Parallel.ForEach loop?

I am interested in running a parallel execution of a web crawler using Selenium ChromeDriver. Encountering problems when attempting to use the same instance of ChromeDriver within a ForEach loop. When trying to access attributes of an HTML document, the ...

Protractor Error: Internet Explorer Launch Error Due to Inconsistent Protected Mode Settings Across Zones

I need help troubleshooting my protractor launch. Here is the code snippet I am currently using: conf.js containing the following: // Sample configuration file. exports.config = { // Address of running selenium server. seleniumAddress: 'http://lo ...

Python Selenium is having trouble finding the elements

I've been struggling for hours to extract the specific text from a variety of elements on a website. I attached 2 images in hopes that they will help in identifying these elements by their similarities, such as having the same class name. The black un ...

Guide to creating a new browser tab with Selenium WebDriver in Java

Is there a way to launch a new tab within the current Firefox browser using Selenium WebDriver (also known as Selenium 2) in Java? ...

Discovering the location of a button on a website: Tips and tricks

Currently, I am extracting data from the following webpage: My task is to click a button in order to access the reviews. When using Google Chrome, this is the XPATH path that I obtain: //*[@id="myspanpos"] However, upon attempting to execute the script ...

What methods does Ofbiz use to manage sessions?

Excuse my ignorance, but I am new to the world of web development. I am currently working on an application called OFBench which utilizes the Selenium library to mimic user browsing behavior on a website. The website is designed using the Ofbiz template w ...

Encountering issues with downloading necessary dependencies

I'm encountering issues downloading junit and Selenium dependencies in IntelliJ. I've installed IntelliJ on my work laptop, which requires a proxy connection to access the internet. I've entered all the proxy details in the IDE and can succe ...

Navigate through a data grid using Selenium browser automation

I am working with a table from the Ontario Government Employee Directory and I am having difficulty finding the xpath to loop through the data. The table does not have an ID. When inspecting the elements, I see the following structure: <table title="r ...

When attempting to automate tasks with selenium, I encountered a problem where the mouseover function was not functioning

Currently, I am working on automating a website and facing an issue while trying to access a specific submenu item by hovering over a menu. After extensive research, I found that using mouseover would be the best approach since the submenu only appears w ...

Extracting YouTube Videos Using Python and Selenium

My friend asked me to scrape all the videos from 'TVFilthyFrank'. I have access to all the links for each video. I want to determine the size of each video in MB and then proceed with downloading them. However, using driver.get(VIDEO_URL) and ext ...

selenium.common.exceptions.WebDriverException: Oops! Unable to locate the Opera binary using OperaDriver in Selenium with Python. It seems we have encountered an

I attempted to run a simple Python script that was supposed to open Google, but encountered some difficulties. After installing selenium with pip and adding the OperaDriver to my Python path as instructed on the Selenium page, I still couldn't get it ...

What methods are available for transforming my Python GUI program into a desktop application?

Recently, I created a Python program with a GUI included. Now, I'm looking to turn this program into a desktop app that can be opened without the need for a text editor or command line execution. The program itself searches for and plays the first vid ...

The clickable element is unresponsive in Protractor

Has anyone encountered difficulties interacting with elements in a modal popup? My current setup includes ChromeDriver 2.46, and all my tests involving modal popups are failing on Chrome 74. I keep encountering the following error message: The element is ...