0

I am trying to select and click a link on a web webpage using Selenium. The url is this test site. When I used regular element locator or xpath or cssSelectors:

//div[@class="welcmewrap"]/div/div[3]/div/div[2]/div/div[2]/span[2][contains(text(), "Know More...")]

The chropath showed the message:

It might be child of svg/pseudo element/comment/iframe from different src. Currently ChroPath doesn't support for them.

Similarly, running the methods on selenium as below:

WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();

driver.get("https://netbanking.hdfcbank.com/netbanking/");

//method 1  
driver.findElement(By.xpath("//span[@class='lightbluecolor'][contains(text(), 'Know More...')]"));

//method 2  
driver.findElement(By.xpath("//div[@class=\"welcmewrap\"]/div/div[3]/div/div[2]/div/div[2]/span[@class= ‘lightbluecolor’] [contains(text(), \"Know More...\")]")).click();

System.out.println("know more click");

...returned:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //span[@class='lightbluecolor'][contains(text(), 'Know More...')]

When I investigated further, it appears to be a nested frame issue but I couldn't find an "iframe" tag on the webpage source.

How to reach that element?

James Z
  • 12,209
  • 10
  • 24
  • 44
jugunnu
  • 1
  • 1

2 Answers2

0

The element with text as Know More on the HDFC Bank NetBanking landing page is within a <frame>.


Solution

To click on the element with text as Know More you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.

  • Induce WebDriverWait for the desired elementToBeClickable.

  • You can use the following Locator Strategies:

  • Using xpath:

    WebDriver driver = new FirefoxDriver();
    driver.get("https://netbanking.hdfcbank.com/netbanking/");
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@name='login_page']")));
    
  • Browser Snapshot:

KnowMore


References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
WebDriver driver;
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");
        driver=new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //Actions class method to drag and drop
        //driver=new ChromeDriver();
        driver.get("https://netbanking.hdfcbank.com/netbanking/");
        driver.switchTo().frame("login_page");
        WebElement frame = driver.findElement(By.xpath("(//a[contains(text(),'Know')])[2]"));
        frame.click();

This know more webelement is present inside the frame so we need to switch to that frame then click on know more link
Dinesh
  • 24
  • 4