so I have never had an issue like this before so this goes a bit over my head. I am trying to write a java program that checks store availability in a site like staples. http://www.staples.com/Kodak-EasyShare-Z5010-Digital-Camera/product_369838 After I go to a site like that and click "Check in Store Availability", a javascript window pops up. Using firebug and firepath, I found the zipcode input box has an xpath of ".//*[@id= zipCode ]". When I try to enter information into that box in my program, webdriver cannot find the text box. An additional note is that I cannot actually find the box with firebug either unless I click it first.
我的问题是:我如何用 Webdriver 导航到那个盒子? 我为此使用2.21。如果有人愿意尝试运行我的代码, 我打破了关键部分, 进入了一个可运行的程序 。
import java.util.ArrayList;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class Test{
public static void main(String[] args) throws InterruptedException{
ArrayList<String> pIDs = new ArrayList<String>();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);
String link, availStr;
String output = null;
//Gets me through their initial zipcode prompt before I can see any products on site
//---------------------------------------
String url = "http://www.staples.com/Tablets-Tablets/cat_CL165566";
driver.get(url);
driver.findElement(By.xpath(".//*[@id= zip ]")).sendKeys("55555");
driver.findElement(By.xpath(".//*[@id= submitLink ]")).click();
try {
Thread.sleep(1000);
时 时 catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
时 时
//--------------------------------------------
driver.get("http://www.staples.com/Kodak-EasyShare-Z5010-Digital-Camera/product_369838");
System.out.println("Now on item: " + driver.getTitle() + " " + driver.findElement(By.xpath(".//*[@class= note none ]")).getText() + "
");
driver.findElement(By.xpath("//li[@class= storeavail ]/a")).click();
Thread.sleep(400);
driver.findElement(By.xpath(".//*[@id= zipCode ]")).sendKeys("90210");
driver.findElement(By.xpath(".//*[@id= searchdistance ]/div/a")).click();
driver.quit();
时 时
时 时