2016-04-27 7 views
0

ウェブページ上のプルダウンメニューを特定できません。ドロップダウンメニューは表の中にあります。テーブル内のドロップダウンメニューを特定する(Selenium in Python)

<table cellspacing="9" cellpadding="0" border="0" summary="This table is for page layout only"> 
    <tbody> 
     <tr> 
      <td width="131" valign="top" bgcolor="#444444" align="left" rowspan="2"></td> 
      <td valign="top" align="left"> 
       <map id="events" name="events"></map> 
       <img height="468" width="544" border="0" alt="HALOE events for 10-OCT-1995 displayed on a cylindrical projection" usemap="#events" src="../coverage/index.php?boxaction=drawLatLonPlot&u=1490"></img> 
       <br></br> 
       <form name="chooseEvents" action="index.php" method="post"> 
        <span class="subtitle" style="color:#ff3333"></span> 
        <select size="1" name="param"> 
         <option selected="selected" value=""></option> 
         <option value="1"></option> 
         <option value="2"></option> 
         <option value="3"></option> 
            . 
            . 
            . 
        </select> 

私が興味のドロップダウンメニューは次のとおりです:Inspect Elementは以下の通りです

<select size="1" name="param"> 

私はこれを行うための他のexamplesを見てきましたが、Inspect Elementテキストは、ドロップダウンメニューを識別するために、類似の形式ではありません。これはウェブページ上の唯一のドロップダウンメニューです。 PythonでSeleniumを使用してこのドロップダウンメニューの値を見つけて選択するにはどうすればよいですか?

これまでのところ、私はウェブページを開くことができますが、そのドロップダウンメニューを選択/操作することに問題があります。私の現在のコードは次のとおりです。

from selenium import webdriver 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support.select import Select 

import unittest 
import time 

class SelectOptionTest(unittest.TestCase): 

    def setUp(self): 
     self.driver = webdriver.Firefox() 
     self.driver.get("http://haloe.gats-inc.com/download/index.php?boxaction=dspProfiles&u=1490") 

    def test_SelectOptionn(self): 
     driver = self.driver 
     dropdown = driver.find_element_by_css_selector("ul.level1") 
     print(dropdown) 

if __name__=='__main__': 
    unittest.main() 
あなたは Selectクラスを使用して name属性とオプションの選択を使用してドロップダウンを見つけることができます

答えて

1

dropdown = driver.find_element_by_name('param') 
select = Select(dropdown) 
select.select_by_value(value) 
関連する問題