我在使用 Selenium 导航“搜索”按钮时遇到问题。我需要单击“搜索”按钮,然后返回初始页面并再次单击它。我的代码导航此按钮并在第一次完美点击它,然后网页返回到初始 URL。然后它应该再次导航同一个按钮,但是,它不起作用......我使用了许多不同的方式(xpath等)这里有什么问题?这是我的完整代码。可以将其复制粘贴到 eclipse 中,看看我在说什么:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Search {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver",
"chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
// Getting the initial page
driver.get("http://pqasb.pqarchiver.com/chicagotribune/advancedsearch.html");
driver.findElement(By.xpath("//input[@value='historic']")).click();
WebElement element = driver.findElement(By.name("QryTxt"));
element.sendKeys("issue");
driver.findElement(
By.xpath("//input[@value='Search'][@onclick='return checkinput(this.form, 0);'][@type='button']"))
.click();
// Getting back to the initial page
driver.get("http://pqasb.pqarchiver.com/chicagotribune/advancedsearch.html");
driver.findElement(
By.xpath("//input[@value='Search'][@onclick='return checkinput(this.form, 0);'][@type='button']"))
.click();
/**
* This command does not execute. It is supposed to click on the button
* "SEARCH" It worked well in the above identical code line, however now
* it just does not recognize the existence of this button How can I
* overcome this issue? I tried navigating this button by all different
* means (xpath etc...)
*/
}
}