Tips for changing to a frame and retrieving an element within it

Looking to access the element containing the text Deprecated within the website "" using selenium in the Chrome browser.

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(driver.findElement(By.name("classFrame"))));
driver.switchTo().frame("classFrame");

The code above is resulting in an error for me. Any suggestions on how to correct this?

Answer №1

You were almost there. Utilizing

frameToBeAvailableAndSwitchToIt()
not only pauses but also shifts Selenium's attention to the content within the <iframe>. Therefore, in order to execute a click() on the element containing the text Deprecated since the target elements exist within a <frame>, you need to:

  • Implement WebDriverWait for the specified frameToBeAvailableAndSwitchToIt.
  • Implement WebDriverWait for the intended elementToBeClickable.
  • You can opt for any of the listed Locator Strategies:

    • cssSelector:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame[name='classFrame']")));
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.topNav a[href^='deprecated-list']"))).click()
      
    • xpath:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@name='classFrame']")));
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='topNav']//a[starts-with(@href, 'deprecated-list')]"))).click();
      

For further insights, refer to this enlightening discussion on Approaches to dealing with #document under iframe

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

When utilizing Grid, is it necessary for us to include the URL of every node in every test case?

How can you specify on which node to execute each test case? For instance: Let's say I have set up a grid HUB on system with IP a1 and have connected b1, b2, b3 to the hub a1. If I have a class containing tests tc1, tc2, tc3, tc4, tc5 etc.., ...

Leveraging TestNG for organizing Selenium tests WITHOUT running them in parallel

Hello everyone, this is my first time posting a question here and I would really appreciate some help. I have been utilizing TestNG in my framework for quite some time now. Today, my query is regarding the configuration of testng.xml to prevent tests from ...

Python's Selenium is having trouble properly displaying the website in its entirety

After attempting the following code to open a website using Selenium in Python: driver = webdriver.Chrome(r"..\chromedriver_win32\chromedriver.exe") driver.get("https://example.com") I encountered an issue where the website o ...

Selenium Webdriver seems to be erasing the content from fields that were filled using the sendKeys method

While testing the webpage, I noticed that when using knockout, I encountered a unique issue. Other pages on our site that do not use knockout did not present the same problem. The scenario unfolds when the page loads, required fields are filled in, and the ...

When attempting to click a button using Python, an error may be encountered known as TimeoutException in the selenium module

I am encountering an error while using the Selenium package to automate button clicks on a website. The specific error message is: selenium.common.exceptions.TimeoutException: Message: Below is the code snippet that I'm attempting to execute: impor ...

How to Develop a Custom getText() Function for a Selenium Element?

Creating a custom Selenium getText() method that can retrieve either the node text or the node plus child text of an element is my current challenge. The default behavior of Selenium appears to utilize the Xpath .//string() method which includes the text o ...

Press a radio button using Python Selenium

Struggling to choose a radio button with Python Selenium here. I've exhausted all possible solutions found online, but none seem to work for the specific website I'm dealing with. Here's the complete code snippet: import time from selenium ...

Getting the test report link from Jenkins using the surefire-reports testng-results.xml file

Currently, my Jenkins instance is set up to run multiple builds. After each build, a testng-results.xml file is created at target/surefire-reports/testng-results.xml. To review the results, I usually visit the HTML report on the Jenkins job homepage, whic ...

Scraping a p tag lacking a class attribute with the help of BeautifulSoup4 (Bs4)

I am attempting to scrape this information from a website: enter image description here Within the HTML, there is a div tag with a class. Inside that div tag, there is another div tag and then a lone p tag without a class. My objective is specifically to ...

Guide to selecting the initial index in search drop down with selenium using C#

IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://www.yahoo.com"); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); driver.FindElement(By.XPath(" ...

Sending Angular 4 POST request to Java Spring Controller via HTTP

Hey there, I'm looking to pass a string from my Angular 4 post request to my Java Spring MVC controller and get its value returned. In the Angular 4 function: let body = 'example' http .post('favourite', body) .subscribe( ...

What could be causing my wait method to not actually wait for the full 30 seconds?

Why is my wait method not waiting for 30 seconds? I want my method to have a timeout of 30 seconds if it cannot find the element. Currently, it just returns true or false immediately without any timeout. Any suggestions on how to fix this? public boo ...

Using compound class names is disallowed - Java Selenium

I need help locating the following button, which is an ant controller. <li class="ant-picker-ok"><button type="button" class="ant-btn ant-btn-primary ant-btn-sm"><span>Ok</span></button></li> ...

Determining the Clickability of a Fully Covered WebElement Using Selenium

I have a pair of divs positioned absolutely <div id="4711" style="position:absolute;top:0px;bottom:0px;left:0px;right:0px;background-color:red">Visible later</div> <div id="4712" style="position:absolute;top:0px;bottom:0px;left:0px;right:0p ...

What is the most effective way to structure my project files for optimal organization and efficiency according to industry standards?

As a newcomer to automation, I have been honing my skills with Selenium and now want to expand into creating a complete automation framework setup. This includes incorporating Selenium, Cucumber, Jenkins, and potentially adding a reporting tool down the li ...

Jenkins is unable to open an actual browser in Ubuntu 16.04

My selenium script successfully launches the chrome browser, navigates to a website, and performs basic checks. However, when attempting to run the same script locally through Jenkins, an error occurred: selenium.common.exceptions.WebDriverException: Mes ...

Locate the span element that holds text contents

I stumbled upon an element concealed somewhere on a webpage: № 81776925 This number (81776925) holds great significance for me. https://i.stack.imgur.com/061jI.png My xpath: "//span[contains(text(), ‘№ 81776925’)]" No luck in locatin ...

Navigating Inconsistent Modals with Selenium Python Bindings

I'm currently facing an issue while filling out a form on a website that adapts its versions based on different factors like language and location. I am using the same Firefox profile for all requests, and the previously selected information is stored ...

Locate an original identifier using Selenium WebDriver

In search of a distinctive identifier for the "update profile picture button" on my Facebook account to utilize it in automation testing with Selenium WebDriver and Java. I attempted driver.findElement(By.className("_156p")).click();, but unfortunately, i ...

Automating Jenkins interfaces using selenium automation techniques

I am looking to create a system that can automatically detect any flakiness in my test scripts. I need to track the pass percentage of a certain number, let's say n builds, for a specific job. Unfortunately, using Xpaths to collect this data is not pr ...