簡體   English   中英

我正在嘗試從下拉列表中選擇值,但為什么不能呢?

[英]I am trying to select value from drop down , but i can't why?

我的問題是我想選擇下拉菜單“國家”“美國”![這是一個下拉菜單] [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")));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM