[image][1]
框架中出现的按钮,我已经编写了用于切换框架的代码并点击了facebook按钮但是没有执行点击操作,给我的html代码请帮帮我
Html框架
<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代码
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();
答案 0 :(得分:0)
以下是您需要做的事情:
您的可能代码可能如下所示:
/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);
如果这有助于您,请告诉我。