English 中文(简体)
找不到带有 Webdriver 的 Javascrip 框架
原标题:Cannot find javascript frame with webdriver

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();
时 时

时 时

最佳回答

您应该切换到框架框, 然后再处理框架中的任何元素...

driver.switchTo().frame(weblement/nameofframe)
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签