【发布时间】:2015-10-15 10:10:57
【问题描述】:
我正在创建一个可重用的函数来处理帧,并且想点击 Fantasy11 网站上的“我不是机器人”复选框。它抛出异常 - 。 请帮忙。。
我尝试了很多,但都在努力获得正确的结果。
import java.util.List;
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;
public class section9frames {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver=new FirefoxDriver();
driver.get("https://fantasycricket.dream11.com/IN/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
int number=findframenumber(driver,By.xpath(".//*[@id='recaptcha-anchor']/div[5]"));
driver.switchTo().frame(number);
driver.findElement(By.xpath(".//*[@id='recaptcha-anchor']/div[5]")).click();
driver.switchTo().defaultContent();
int number1=findframenumber(driver,By.xpath(".//*[@id='recaptcha-verify-button']"));
driver.switchTo().frame(number1);
driver.findElement(By.xpath(".//*[@id='recaptcha-verify-button']")).click();
}
public static int findframenumber(WebDriver driver,By by) {
int i;
int framecount=driver.findElements(By.tagName("iframe")).size();
for (i=0;i<framecount;i++) {
driver.switchTo().frame(i);
int count=driver.findElements(by).size();
if(count>0) {
break;
} else{
}
}
driver.switchTo().defaultContent();
return i;
}
}
【问题讨论】:
-
有什么异常?
-
线程“主”org.openqa.selenium.NoSuchFrameException 中的异常:无法定位框架:1
-
所以你正在编写代码来创建一个机器人来绕过试图阻止机器人的功能......不要那样做。
标签: java selenium xpath selenium-webdriver webdriver