0

I am not able to click a link in a frame in run mode. First I switched to Frame and then click on a link. After clicking the link, I want to click on another link on the same frame. But not able to click on the second link. In Debug mode, I am able to click both the link.

Used URL: http://demo.guru99.com/selenium/deprecated.html

There are three frames on the page and I switch to frame named "classFrame". On the Frame, I click on the link named "Deprecated". I got all the content of "Deprecated" link. Now I want to click on "Overview" link where I was before. But I am not able to click on link named "Overview". Please help me to click on the second link "Overview". I am using following code:

    System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
    WebDriver driverChrome = new ChromeDriver();
    WebDriverWait webWaitVar = new WebDriverWait(driverChrome, 1000);
    driverChrome.get("http://demo.guru99.com/selenium/deprecated.html");

    driverChrome.switchTo().frame("classFrame");

    driverChrome.findElement(By.linkText("Deprecated")).click();
    WebElement linkOverview = driverChrome.findElement(By.linkText("Overview"));
    webWaitVar.until(ExpectedConditions.visibilityOf(linkOverview));
    driverChrome.findElement(By.linkText("Overview")).click();

For page HTML code, Please refer the link as I am not able to paste it here. Thank you very much

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Achiver
  • 51
  • 2

1 Answers1

0

To click() on the element with text as Deprecated within the url http://demo.guru99.com/selenium/deprecated.html and again click() on the element with text as Overview, as the the desired element is within a <frame> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:

    • cssSelector:

      System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
      WebDriver driverChrome = new ChromeDriver();
      driverChrome.get("http://demo.guru99.com/selenium/deprecated.html");
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame[name='classFrame']")));
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.topNav a[href^='deprecated-list']"))).click();
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.topNav a[href^='overview-summary']"))).click();
      
    • xpath:

      System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
      WebDriver driverChrome = new ChromeDriver();
      driverChrome.get("http://demo.guru99.com/selenium/deprecated.html");
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@name='classFrame']")));
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='topNav']//a[starts-with(@href, 'deprecated-list')]"))).click();
      new WebDriverWait(driverChrome, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='topNav']//a[starts-with(@href, 'overview-summary')]"))).click();
      

Here you can find a relevant discussion on Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352