找不到带有webdriver的javascript框架
所以我以前从来没有遇到过这样的问题,所以这有点让我头疼。我正在尝试编写一个java程序,用于检查staples等站点中的商店可用性。 当我进入这样一个站点并单击“Checkin Store Availability”后,会弹出一个javascript窗口。使用firebug和firepath,我发现zipcode输入框的xpath为“/*[@id='zipcode']”。当我尝试在程序中的该框中输入信息时,webdriver找不到文本框。另外一点需要注意的是,除非我先单击firebug,否则我实际上也找不到它 我的问题是:如何使用webdriver导航到该框?我正在为此使用selenium 2.21。如果有人想尝试运行我的代码,我将关键部分分解成一个可运行的程序找不到带有webdriver的javascript框架,java,javascript,html,selenium,webdriver,Java,Javascript,Html,Selenium,Webdriver,所以我以前从来没有遇到过这样的问题,所以这有点让我头疼。我正在尝试编写一个java程序,用于检查staples等站点中的商店可用性。 当我进入这样一个站点并单击“Checkin Store Availability”后,会弹出一个javascript窗口。使用firebug和firepath,我发现zipcode输入框的xpath为“/*[@id='zipcode']”。当我尝试在程序中的该框中输入信息时,webdriver找不到文本框。另外一点需要注意的是,除非我先单击firebug,否则我实
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() + "\n");
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();
}
import java.util.ArrayList;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.firefox.FirefoxProfile;
公开课考试{
公共静态void main(字符串[]args)引发InterruptedException{
ArrayList pIDs=新的ArrayList();
FirefoxProfile profile=新的FirefoxProfile();
setPreference(“general.useragent.override”,“someuastring”);
WebDriver=新的FirefoxDriver(配置文件);
字符串链接,availStr;
字符串输出=null;
//在我可以在网站上看到任何产品之前,让我通过他们最初的zipcode提示符
//---------------------------------------
字符串url=”http://www.staples.com/Tablets-Tablets/cat_CL165566";
获取(url);
findelelement(By.xpath(“./*[@id='zip'])).sendKeys(“55555”);
findElement(By.xpath(“.//*[@id='submitLink']”)。单击();
试一试{
睡眠(1000);
}捕捉(中断异常e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
//--------------------------------------------
驱动程序。获取(“http://www.staples.com/Kodak-EasyShare-Z5010-Digital-Camera/product_369838");
System.out.println(“立即打开项:“+driver.getTitle()+”+driver.findElement(By.xpath(“./*[@class='note none']”)。getText()+”\n”);
findElement(By.xpath(“//li[@class='storeavail']/a”))。单击();
睡眠(400);
findelelement(By.xpath(“./*[@id='zipCode']”);
driver.findelelement(By.xpath(“./*[@id='searchdistance']]/div/a”)。单击();
driver.quit();
}
}在处理框架中的任何元素之前,应切换到框架
driver.switchTo().frame(weblement/nameofframe)
在处理框架中的任何图元之前,应切换到框架
driver.switchTo().frame(weblement/nameofframe)
有没有具体的方法让我找到框架的名称?对不起,我对使用硒元素还不太熟悉。试试这个。driver.switchTo(driver.findElement(By.xpath(//iframe[@id='overlayframe']))。我没有测试这个,这是你问题中的链接。有没有具体的方法让我找到框架的名称?对不起,我对使用selenium很陌生。试试这个。driver.switchTo(driver.findElement(By.xpath(//iframe[@id='overlayframe'])).我没有测试这个,这是你问题中的链接