我想点击跨度内的单选按钮。试图执行:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromeDriver = webdriver.Chrome()
chromeDriver.get('https://www.flytap.com/pt-br/')
#Works Fine
chromeDriver.find_element_by_id('origin')
origin.click()
origin.clear()
origin.send_keys('(RIO) Rio De Janeiro - todos os aeroportos , Brasil')
origin.click()
#Where I got the error
milesBox = chromeDriver.find_element_by_id("booking-type-2").click()
#Also tried:
milesBox = chromeDriver.find_element_by_id("booking-type-2").send_keys(Keys.ENTER)
#And, finally:
milesBox = chromeDriver.find_element_by_id("booking-type-2").send_keys(Keys.SPACE)
这是我得到的错误:
ElementNotVisibleException: Message: element not visible
HTML code:
<!-- Payment Methods START -->
<fieldset id="booking-payment-drag" class="booking-payment">
<div class="toolbar-radio-wrapper">
<legend class="ipt-label">Reservar com:</legend>
</div>
<div class="toolbar-radio-wrapper">
<div class="radio">
<span class="checked"><input type="radio" id="booking-type-1" name="booking-type" value="1" checked></span>
</div>
<label for="booking-type-1" class="ipt-label">Dinheiro</label>
</div>
<div class="toolbar-radio-wrapper js-country-not-eligible">
<div class="radio">
<span class=""><input type="radio" id="booking-type-2" name="booking-type" value="2"></span>
</div>
<label for="booking-type-2" class="ipt-label">Milhas</label>
</div>
<div class="toolbar-radio-wrapper">
<div class="radio is-disabled js-country-eligible">
<span class=""><input type="radio" id="booking-type-3" name="booking-type" value="3" disabled></span>
</div>
<label for="booking-type-3" class="ipt-label">Miles&Cash</label>
</div>
</fieldset>
答案 0 :(得分:0)
似乎origin
元素的下拉列表中包含您要点击的单选按钮。也许你可以改变操作的顺序?单击destination
元素也会打开单选按钮所在的部分,但它似乎无法覆盖它。这是单击该单选按钮的快速示例,然后您可以在之后填写origin
输入。
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.flytap.com/pt-br/')
destination = driver.find_element_by_id('destination')
destination.click()
miles_box = driver.find_element_by_id('booking-type-2')
miles_box.click()
答案 1 :(得分:0)
您可以使用此xpath
//div[@class='radio']//span//input[@id='booking-type-1']
//div[@class='radio']//span//input[@id='booking-type-2']
//div[@class='radio is-disabled js-country-eligible']//span//input[@id='booking-type-3']
答案 2 :(得分:0)
根据您共享的 HTML ,点击<label>
旁边的单选按钮,文字为 Milhas ,您可以使用以下代码行:
chromeDriver.find_element_by_xpath("//input[@id='booking-type-2' and @name='booking-type']").click()