【发布时间】:2016-01-19 10:13:54
【问题描述】:
我有一个带有一些单选按钮的网页。我正在尝试单击一个单选按钮,但它没有单击并抛出
完整的错误是:
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
MainPageLocators 中按钮的定位器的 XPATH 是:
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。它不应该说 Element 不可见。我不知道为什么我不能点击这个按钮。 它在网页上可见。
如何单击此单选按钮? 一些帮助表示赞赏。
谢谢, 里亚兹
【问题讨论】:
标签: python-2.7 selenium xpath selenium-webdriver