Reputation: 135
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.
My question is: how do I navigate to that box with webdriver? I am using selenium 2.21 for this. In case anyone feels inclined to try running my code, I broke the key part out into a runnable program
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();
}
}
Upvotes: 0
Views: 1345
Reputation: 4949
You should switch to the frame before working on any elements in the frame..
driver.switchTo().frame(weblement/nameofframe)
Upvotes: 3