Navigating through frames in Selenium can be a bit tricky,

I am having trouble logging into this website.

Upon loading the page, a frame appears.

I have attempted to switch to the frame without success.

public void logon(String Username,String Password,String trns)
{
    Configuration.driver.get(Configuration.URL);

    Configuration.driver.manage().timeouts().implicitlyWait(8,TimeUnit.SECONDS);
    Configuration.driver.switchTo().
    //Configuration.driver.findElement(By.xpath("//a[@text()='Close Window']")).click();
    usrId.sendKeys("Username");
    pswd.sendKeys("Password");
    tranId.sendKeys("trns");
    logOn.click();
}

Answer №1

Looking for code to switch frames? Search first before asking.

//Switch to Iframe
 WebElement iframe = driver.findElement(By.xpath("Xpath of frame"));
 driver.switchTo().frame(iframe);  

 //Perform your Task.

 driver.switchTo().defaultContent();// Iframe is Switched to Main Again 

For help with frame switching, check out this helpful resource:- Click here

Hi Ketan. Having trouble with your code? It might be due to a wait issue. Allow some time in your code after clicking continue in the pop-up window.

Learn more about waits

Here's a tested working code to resolve your issue:

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class userId {

    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen");
        System.out.println("Entered Url");
        WebElement frame=driver.findElement(By.xpath("//*[@id='lightbox_iframe_cookieBanner']"));
        driver.switchTo().frame(frame);
        driver.findElement(By.xpath("//*[@id='lightboxarea']/div/div/a[1]")).click();
        driver.switchTo().defaultContent();
        driver.findElement(By.xpath("//*[@id='usrId']")).sendKeys("hari");
        System.out.println("Entered the userid");
        driver.findElement(By.xpath("//*[@id='pswd']")).sendKeys("Password");
        System.out.println("Entered the Password");    
    }
}

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

What is the correct way to loop through data and write it to a CSV file in Python?

Using the code snippet below, I am scraping content from a webpage with the intention of writing it to a CSV file. Initially, this portion of the code worked fine. However, now that my data is formatted differently, when I view it in Excel, the output appe ...

Using Selenium to navigate to Google and selecting the Images link, followed by clicking on the first image

Below is the code I'm working with. When I run it: Firefox opens - as expected Navigates to Google.com - as expected Types "Pluralsight logo" in the search box - as expected However, after that, I see the Google.com page with an empty search box. W ...

Having trouble getting the newest Edge/Chromium release to function properly with selenium in Java

We are currently running Selenium automated tests for Chrome, Firefox, and pre-Chromium Edge. Now, we want to execute the same test suite on the latest version of Edge. Selenium (Java) - 4.0.0-alpha-4 Edge - 79.0.309.71 I have experimented with different ...

Tips on storing data in Excel using pandas?

My script performs the following actions: 1. Accesses the website 2. Gathers links and stores them in a dictionary 3. Navigates through the saved links to extract elements, which are then stored in another dictionary 4. Finally, it saves the extracted ...

Concerns arise when dealing with a jar file that contains external libraries

I am facing an issue with starting my program from a jar file that I created. It runs perfectly fine when launched from IntelliJ, but when I try to start it from the jar file, it fails to work. I used IntelliJ to create the jar and my project was built usi ...

Retrieving data from Mouse Hover popup with Selenium in Python

I have a project where I'm utilizing Selenium to automate tasks on a website. There is an interactive mouse hover box that appears to provide relevant information for users. Below is the HTML code snippet for the mouse hover: <td align="center ...

Issue resolved: Unable to select element with <div>linktext</div> despite trying all possible solutions

Here is a div with a popup overlay: <div class="tutorial-button tutorial-button-ok tt-close">Later</div> Check out the source code for this element: <a class="match-button match-button-close" href="javascript:void(0);" onclick="matchingLa ...

Having trouble accessing the link from the dropdown list in Selenium

While trying to select a link from a dropdown menu, I am facing an issue with Selenium. The element is being located successfully, but it cannot be interacted with and the following exception is thrown: Error in thread "main" org.openqa.selenium.ElementNo ...

Using Selenium in Java to interact with popup elements

Attempting to retrieve and interact with pop-up/alert elements using selenium in Java has been a bit challenging for me. Below is the code snippet I have been working on: import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import ...

Navigating between browser sessions

I am facing a challenge with my Selenium tests where I need to activate different browser windows that are running in parallel. How can I simulate a user click on the taskbar to make a specific window active? By default, the first instance of Selenium&apo ...

Automating the process of clicking an element within an iframe using Selenium

Is there a way to interact with an element in this iframe without having a name or ID? I keep receiving a null pointer exception when trying to determine the number of iframes. Specifically, I am trying to click on the 'Set up Index patterns' lin ...

Error encountered in main thread: Illegal State Exception. The path to the driver executable needs to be defined using the webdriver.gecko.driver system

Despite trying various solutions from previous related issues, I have exhausted all options but continue to encounter the same error across FireFox, Chrome, and Internet Explorer. import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; im ...

Encountered difficulty in generating a Maven Project for automation of selenium tests

Error stack: Error: There was an issue retrieving the plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7. Parsing of the plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7 failed (C:\Users\lenovo ...

Ways to minimize redundant code in my collections of elements to conceal (Java/webDriver)

In my Java Selenium test suite, I have a method that hides dynamic elements on a webpage to prevent failures during screenshot comparisons. I am looking to streamline this method by reducing repeated code sections. Currently, I am using findElements to loc ...

How to use selenium to download and rename multiple files from a URL

Trying to extract data from a link by inserting the list of "tickers" into the URL code below. An error occurs when attempting to loop through the tickers list within the for loop of the URL. from selenium import webdriver from selenium.webdriver.chrome.s ...

Confirm a chosen dropdown option by its value in Selenium utilizing C#

I need to confirm the selected dropdown option by its value using the code below: SelectElement selectElement = new SelectElement(Base.driver.FindElement(by)); selectElement.SelectByValue(value); However, I am facing a challenge in verifying if the corre ...

The @FindBy annotation in Webelement fails to return a valid reference, resulting in a

When I try to invoke the method Spage.editExButton(int ID), I encounter an issue where WebElement first is null and an error occurs. I have already defined it using the @FindBy annotation, so why is it still null? To work around this problem, I have to exp ...

Ways to resolve the stale element issue on a webpage without the need to refresh the

Looking to gather information about the different types of Tyres featured on this page. Each tyre comes in various FINITIONS, with individual prices and details. I would like to click on each FINITION type but encounter a problem - upon clicking, the lin ...

Utilizing Python's Selenium for Logging into Accounts

Currently, I am attempting to utilize Selenium with Python for logging into a specific website https://commerce.spscommerce.com/auth/login/ Despite my efforts, none of the xpath's I have utilized successfully located the targeted element. driver = ...