2015-10-20 89 views
0

我有一个单选按钮的网页。我想点击一个单选按钮,但它不点击和投掷硒Python尝试单击单选按钮错误ElementNotVisibleException

完整的错误是:

Traceback (most recent call last): 
    File "C:\Webdriver\ClearCore\TestCases\DataPreviewsPage_TestCase.py", line 48, in test_add_Lademo_CRM_DataPreviews 
    data_previews_page.click_from_file_radio_button_from_options_tab() 
    File "C:\Webdriver\ClearCore\Pages\data_previews.py", line 112, in click_from_file_radio_button_from_options_tab 
    fromfile_radiobutton.click() 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 69, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 448, in _execute 
    return self._parent.execute(command, params) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 196, in execute 
    self.error_handler.check_response(response) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response 
    raise exception_class(message, screen, stacktrace) 
ElementNotVisibleException: Message: Cannot click on element 

我点击按钮的方法是:

def click_from_file_radio_button_from_options_tab(self): 
     fromfile_radiobutton = self.driver.find_element(*MainPageLocators.data_previews_fields_from_File_radioButton_from_options_tab_xpath) 
     fromfile_radiobutton.click() 
     return self 

的XPATH为用于从MainPageLocators该按钮的定位器是:

data_previews_fields_from_File_radioButton_from_options_tab_xpath = (By.XPATH, '//span[@class="gwt-RadioButton block"]/label[contains(text(), "From file")]/../input') 

的HTML是:

<table class="gwt-DisclosurePanel gwt-DisclosurePanel-open" cellspacing="0" cellpadding="0"> 
    <tbody> 
     <tr> 
      <tr> 
       <td align="left" style="vertical-align: top;"> 
        <div style="padding: 0px; overflow: hidden;" aria-hidden="false"> 
         <div class="content" aria-hidden="false"> 
          <span class="gwt-RadioButton block"> 
           <input id="gwt-uid-163" type="radio" name="fields" value="on" tabindex="0" checked=""/> 
           <label for="gwt-uid-163">From file</label> 
          </span> 
          <span class="gwt-RadioButton block"> 
          <span class="gwt-RadioButton GPI5XK1CET GPI5XK1CFT"> 
          <input class="gwt-IntegerBox" type="text" disabled="" size="3"/> 
          <span class="gwt-RadioButton block"> 
         </div> 
        </div> 
       </td> 
      </tr> 
     </tbody> 
    </table> 

它在HTML中不显示hidden = True。它不应该说元素不可见。我不知道为什么我不能点击这个按钮。 它可以在网页上看到。

我怎样才能点击这个单选按钮? 有些帮助表示赞赏。

感谢, 里亚兹

回答

0

我不相信你的XPath是正确的。我会尝试这样的事情。我无法从有限的HTML中知道这是否足够独特。

fromfile_radiobutton = self.driver.find_element_by_css_selector("input[type='radio'][name='fields']") 
fromfile_radiobutton.click() 
+0

谢谢您的建议。这不是唯一的,因为有其他单选按钮。我已经要求开发者为表格添加一个ID。然后,我可以从表ID开始构建xpath。 –

+0

只是为了好玩......试试这个'self.driver.find_element_by_css_selector(“table.gwt-DisclosurePanel.gwt-DisclosurePanel-open input [type ='radio'] [name ='fields']”)''。我添加了一个可能足以找到收音机的“TABLE”引用。 – JeffC