我試圖模擬幾個點擊爲我的新程序,但我堅持最後一件事!無法讓硒單擊一個元素
我已經設法讓硒打開頁面,然後點擊顯示一個矩形彈出框的複選框,其中有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