[英]Cannot find javascript frame with webdriver
所以以前我從來沒有遇到過這樣的問題,所以這有點讓我煩惱。 我正在嘗試編寫一個Java程序來檢查釘書釘等網站中的存儲可用性。 http://www.staples.com/Kodak-EasyShare-Z5010-Digital-Camera/product_369838在我進入類似的站點並單擊“簽入商店可用性”后,將彈出一個JavaScript窗口。 使用firebug和firepath,我發現郵政編碼輸入框的xpath為“ .//*[@id='zipCode']”。 當我嘗試在程序的那個框中輸入信息時,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() + "\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();
}
}
在處理框架中的任何元素之前,應切換到框架。
driver.switchTo().frame(weblement/nameofframe)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.