2016-04-08 9 views
0

デモサイトで練習テストを作成していますが、ドロップダウンリストから値を選択する際に問題がありますが、要素を見つけることができませんが、正しいですでSelectドロップダウン - Selenium Webdriver

drop_list = @@wait.until { 
      drop = @@driver.find_element :id => '#dropdown_7' 
      drop if drop.displayed? 
      drop.click 
     } 


     options=drop_list.find_element :id => '#dropdown_7' 

     options.each do |i| 
      if i.text == 'American Samoa' 
      i.click 
      break 
      end 

答えて

1

をありがとうございました。これはidが "dropdown_7"の要素と一致するCSSセレクターですが、id属性と一致しません。

それだけで次のようになります。私はルビーでこれを実装しましたどのように

drop = @@driver.find_element :id => 'dropdown_7' 
0

HTML

<select id="dropdown_7" name="dropdown_7" class=" piereg_validate[required]"><option value="Afghanistan">Afghanistan</option> 

Rubyのコード:IDと私は運と同様にIDとCSSセレクタで試してみたが:(私はHTMLと下記のセレンコードを掲載します以下のjavaは方法は、webdriverを選択して使用してオプションをクリックしてドロップダウン

Select dropdown = new Select(driver.findElement(By.id("your id"))); 

    dropdown.selectByVisibleText("option text here"); 

または

dropdown.selectByIndex(1); 

または

dropdown.selectByValue("value attribute of option"); 

ので不要

を選択します。

は、問題は、あなたが "#1 dropdown_7" としてIDを指定していることで、 ムラリ

0

です:リストのオプションをクリックするため

Selenium::WebDriver::Support::Select.new(
    @driver.find_element(:how, :what) 
).select_by(:how, :what) 
0

JavaScriptを使用エグゼキュータ。

public void javascriptclick(String element) 
{ 
    WebElement webElement=driver.findElement(By.xpath(element)); 
    JavascriptExecutor js = (JavascriptExecutor) driver; 

    js.executeScript("arguments[0].click();",webElement); 
    System.out.println("javascriptclick"+" "+ element); 
}