我有一个带有一些单选按钮的网页。我试图点击一个单选按钮,但它没有点击并抛出
完整错误是:
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不可见。我不知道为什么我不能点击这个按钮。 它在网页上可见。
如何点击此单选按钮? 一些帮助表示赞赏。
谢谢, 里亚兹
答案 0 :(得分:0)
我不相信你的XPath是正确的。我会尝试这样的事情。我无法从有限的HTML中判断出这是否足够独特。
fromfile_radiobutton = self.driver.find_element_by_css_selector("input[type='radio'][name='fields']")
fromfile_radiobutton.click()