Selenium Python。点击单选按钮没有任何影响

时间:2014-04-30 14:41:02

标签: python selenium radio-button webdriver

首先抱歉我的英语。

我有一个带收音机按钮的页面。 这是我要点击的按钮的html代码。

<label class="radio-button__radio radio-button__radio_side_right radio-button__radio_next-for-pressed_yes" for="uniq13988671">
    <input id="uniq13988671" class="radio-button__control" type="radio" value="1000">
    <span class="radio-button__text">все</span>
</label>

我的python脚本与selennium:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains as ac

driver = webdriver.Firefox()
driver.get("url_with_elements")
driver.implicitly_wait(20)

my_button = driver.find_element_by_css_selector("input[value='1000']")
ac(driver).move_to_element(my_button).perform()
my_button.click()

此按钮应重新加载包含所有元素(至少1000)的页面,但它不起作用。 没有任何错误和元素响应方法.get_attribute('id')

>>> my_button.get_attribute('id')
u'uniq13988671'

这里是带有单选按钮的行的完整html代码:

<td class="b-layout-table__cell">
    <div class="b-banners-per-page i-bem b-banners-per-page_js_inited" onclick="return {"b-banners-per-page":{"urlObject":{"hash":"","query":{"cmd":"setPageSize","subcmd":"showCamp","cid":"8868621","ulogin":"*mylogin*"},"file":"main.NWluTm99mAw1N.pl","directory":"/registered/","path":"/registered/main.NWluTm99mAw1N.pl","relative":"/registered/main.NWluTm99mAw1N.pl","port":"","host":"direct.yandex.ru","password":"","user":"","userInfo":"","authority":"direct.yandex.ru","protocol":"https","source":"https://direct.yandex.ru/registered/main.NWluTm99mAw1N.pl"},"optimalBannersOnPage":20}}">
        <span class="b-banners-per-page__title">Объявлений на странице: </span>
        <div class="b-banners-per-page__buttons">
            <span class="radio-button radio-button_size_s radio-button_theme_normal i-bem radio-button_js_inited" onclick="return {"radio-button":{}}">
                <label class="radio-button__radio radio-button__radio_side_left" for="uniq13988675">
                <label class="radio-button__radio radio-button__radio_checked_yes radio-button__radio_pressed_yes" for="uniq13988674">
                <label class="radio-button__radio radio-button__radio_next-for-pressed_yes" for="uniq13988673">
                <label class="radio-button__radio" for="uniq13988672">
                <label class="radio-button__radio radio-button__radio_side_right" for="uniq13988671">
                    <input id="uniq13988671" class="radio-button__control" type="radio" value="1000">
                    <span class="radio-button__text">все</span>
                </label>
            </span>
        </div>
    </div>
</td>

以下是“一步一步”的形象 http://i.imgur.com/LYqKyqx.png

我正在寻找其他问题,但他们没有帮助我。 谢谢你的帮助。

ADD :如果我使用Selenium IDE插件for firefox。这个按钮点击不错。

如果需要更多信息 - 请询问。

1 个答案:

答案 0 :(得分:1)

我已经处理了我的问题使用结构:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains as ac

driver = webdriver.Firefox()
driver.get("url_with_elements")
driver.implicitly_wait(20)

# my_button = driver.find_element_by_css_selector("input[value='1000']")
button_parent = driver.find_element_by_xpath("//td[2]/div/div/span/label[5]")
ac(driver).move_to_element(button_parent).perform()
button_parent.click()
ac(driver).send_keys(Keys.SPACE).perform()