我的问题是我想选择下拉菜单“国家”“美国”
![这是一个下拉菜单] [1]
该网址:http://www.autodesk.com/resellers/locate-a-reseller?cntr=US
下面是我的代码,当我运行此代码时,它是一个异常

1.线程“主”中的异常org.openqa.selenium.NoSuchElementException:无法找到元素:

2.原因: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();
            }
        }
    }
}

最佳答案

请使用以下代码切换到iframe:

<iframe id="resellerFrame" style="height: 1300px; width: 100%; border: medium none; "
 scrolling="auto" src="http://autodesk.force.com/plocator?cntr=US&amp;"></iframe>

您可以使用以下语句:
driver.switchTo().frame(driver.findElement(By.id("resellerFrame")));

关于java - 我正在尝试从下拉列表中选择值,但是我为什么不能呢?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26152321/

10-10 08:44