【问题标题】:Selenium Python. Click on radio-button does not any affect硒蟒。单击单选按钮没有任何影响
【发布时间】:2015-02-06 18:55:34
【问题描述】:

首先对不起我的英语。

我有一个带有单选按钮的页面。 这是我要点击的按钮的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>

我的带有 selennium 的 python 脚本:

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

我正在查看其他问题,但它们对我没有帮助。 感谢您的帮助。

添加:如果我将 Selenium IDE 插件用于 firefox。这个按钮点击得很好。

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

【问题讨论】:

  • 您遇到错误了吗?如果是这样,您可以编辑您的帖子并添加错误吗?我猜代码没有找到元素,这可能是由几个不同的问题引起的。如果您尝试单击的元素位于 frameiframe 中,或者该元素加载缓慢。
  • 添加更多信息。成功找到元素。

标签: python selenium radio-button webdriver


【解决方案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()

【讨论】:

    猜你喜欢
    • 2018-11-02
    • 1970-01-01
    • 2021-08-12
    • 2021-12-08
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    相关资源
    最近更新 更多