2015-10-20 87 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