【问题标题】:How to click Radio Button using python Selenium如何使用 python Selenium 单击单选按钮
【发布时间】:2018-04-30 20:43:26
【问题描述】:

我正在尝试单击左侧选项卡中的单选按钮“每月(最终)”。

请找到链接https://socds.huduser.gov/permits/index.html?

这是我尝试过的代码,

from selenium import webdriver
import time

chrome_path = r"/usr/bin/chromedriver"
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.huduser.gov/portal/datasets/socds.html") # Hitting the Site
driver.maximize_window()
driver.find_element_by_xpath("""//*[@id="block-system-main"]/div[4]/div/div/div/div/form[5]/input""").click() #Clicking Buiding Permits Database
time.sleep(10)
### Not working ###
print driver.find_element_by_xpath("""/html/body/form/a[2]/input""").location # Getting the Location of the Element
Radio = driver.find_element_by_xpath("""/html/body/form/a[2]/input""") # Clicking Monthly Final Radio button
Radio.click()
driver.find_element_by_css_selector("body > form:nth-child(2) > a:nth-child(29) > input:nth-child(1)").click()
print "DONE"

【问题讨论】:

  • 请在您的问题中提及问题,而不是在您的代码的 cmets 中。你还没有提到到底出了什么问题。
  • 您在 xpath 中使用了" " "。 " " " 被视为 cmets。
  • @PrakashPalnati, """string""" 不是评论,而是一个简单的字符串

标签: python selenium radio-button


【解决方案1】:

位于iframe 内的单选按钮。为了能够点击它,你应该先切换到iframe:

driver.switch_to.frame('select')
Radio = driver.find_element_by_xpath("""//input[@value="monthlyF"]""")
Radio.click()

【讨论】:

猜你喜欢
  • 2017-08-02
  • 1970-01-01
  • 2019-03-17
  • 1970-01-01
  • 2019-09-01
  • 2020-01-24
  • 2014-02-14
  • 2021-01-31
  • 2020-08-06
相关资源
最近更新 更多