0
[image][1]

The button present in the frame, i have written code for switch the frame and click on the facebook button but the click operation is not performed, give s my html code please help me out

Html frame

<document>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<body id="social_login" class="plugin">
<!--[if IE]><div id="ie"><![endif]-->
<div id="social_login_frame" class="frame">
<div id="content">
<div id="providers" class="providers providers_unpaginated">
<div id="providers_group_1" class="providers_group">
<div class="providers_block" role="application">
<div class="providers_row">
<div id="provider_facebook" class="provider">
<a id="button_facebook" class="button" href="#" rel="nofollow" title="Login with Facebook" role="button" aria-label="Login with Facebook" aria-haspopup="true">
<div id="name_facebook" class="name">Facebook</div>
</div>
<div id="provider_google" class="provider">
<div id="provider_linkedin" class="provider">
</div>
</div>
</div>
</div>
</div>


  [1]: https://i.stack.imgur.com/jXMDe.png

Webdriver code

driver.findElement(By.xpath("//*[@id='contentagent']/div[2]/‌​ul/li[2]/a")).click(‌​); 
Thread.sleep(1000); 
driver.switchTo().frame(0); 
Thread.sleep(500); 
driver.findElement(By.id("button_facebook")).click();
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137

1 Answers1

0

Here is what you need to do:

  1. Get the parent window handle.
  2. Click on the Link.
  3. Get all the Window Handles.(To confirm its a frame/iframe)
  4. Switch to your frame.
  5. Click on the element.
  6. Go back to parent window.

Your probable code may look like:

/First Get parent window,means current window handle
    String parentWindow = driver.getWindowHandle();
    System.out.println("Parent Window Title "+driver.getTitle());
    driver.findElement(By.xpath("//*[@id='contentagent']/div[2]/‌​ul/li[2]/a")).click();
    //Frame Handling begins here
    //Get All Tabs or Window handles and iterate using for each loop
    for(String handle:driver.getWindowHandles()) 
    {
        System.out.println(handle);
        driver.switchTo().window(handle);
     }

    //switch to frame using frame name
    driver.switchTo().frame("your_frame_name"); // replace by your frame name
    String childtFrame = driver.getWindowHandle();
    System.out.println("Child Frame Title "+driver.getTitle());
    driver.findElement(By.id("button_facebook")).click();
    //Go back to Parent window
    driver.switchTo().window(parentWindow);

Let me know if this helps you.

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