我的问题是我要选择下拉“国家”“美国” ![这是一个下拉] [1] 这个网址:http://www.autodesk.com/resellers/locate-a-reseller?cntr=US 下面是我的代码,当我运行此代码时,它是一个异常的
1.线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到元素:
2.Caused by:org.openqa.selenium.remote.ErrorHandler $ UnknownServerException:无法找到元素:
public class Autodesk {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.autodesk.com/");
driver.manage().window().maximize();
driver.findElement(By.linkText("Find a reseller")).click();
// above steps are pass
Thread.sleep(2000);
// I AM FACING THE PROBLEM FROM THIS STEP**("CLICKING ON COUNTRY AND SELECT THE UNITED STATES")**
driver.findElement(By.className("styled_select_small")).click();
//driver.findElement(By.xpath(" //*[@id=j_id0:j_id21:reAssignCountryList']")).click();
//driver.findElement(By.xpath("//span[contains(text(),'Select Industries')]")).click();
//Drop down
List<WebElement> Country = driver.findElements(By.xpath("//*[@id='j_id0:j_id21:reAssignCountryList']//option"));
System.out.println(Country.size());
for(int i=0;i<Country.size();i++){
System.out.println(Country.get(i).getText());
String CountryName = Country.get(i).getText();
if(CountryName.equals("United States")){
Country.get(i).click();
}
}
}
}
答案 0 :(得分:3)
请使用以下标记切换到iframe:
<iframe id="resellerFrame" style="height: 1300px; width: 100%; border: medium none; "
scrolling="auto" src="http://autodesk.force.com/plocator?cntr=US&"></iframe>
您可以使用以下语句:
driver.switchTo().frame(driver.findElement(By.id("resellerFrame")));