我试图模拟几个点击为我的新程序,但我坚持最后一件事!无法让硒单击一个元素
我已经设法让硒打开页面,然后点击显示一个矩形弹出框的复选框,其中有9个按钮。唯一的问题是点击弹出窗口中的按钮!我已检查的XPath了几次,但硒说“没有这样的元素”
这里是我的代码:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class test {
static WebDriver driver;
public static void main(String[] args) {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("default");
driver = new FirefoxDriver(myprofile);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.runelocus.com/top-rsps-list/vote-1858-GrinderScape%20-%20New%20Website%20and%20Great%20Updates!/");
driver.switchTo().frame(1);
driver.findElement(By.xpath("//*[@id='recaptcha-anchor']/div[5]")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.cssSelector("#rc-imageselect-target > table > tbody > tr:nth-child(1) > td:nth-child(2)")).click();
}
}
编辑: 它创建点击复选框后的新元素。我将如何点击它们?
您正试图制作一个机器人,点击“我不是机器人复选框”? – odedsh
您需要切换到该弹出窗口。因为它可能是新窗口。 – MKay
是的,然后我屏幕截图验证码并发送到验证码解决服务。 – joe