我正在尝试点击“CVV”号码字段并在其中输入数字。我正在尝试以下代码:
ui.WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="cvNumber"]'))).click()
self.driver.find_element_by_xpath('//*[@id="cvNumber"]').send_keys('0000')
然而我收到错误
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
这是我想要选择的HTML:
<div class="ncss-container text-color-grey prl0-sm mt2-sm mb2-sm" id="j_c219" data-juno-component="view/forms/creditCardIframeForm/creditCardIframeForm" data-juno-name="creditCardIframeForm"><iframe sandbox="allow-scripts allow-same-origin" class="credit-card-iframe mt1 u-full-width" src="https://paymentcc.nike.com/services/cvv?id=86ac6e90-bf6b-4762-bf2d-d0bc960a37e7&t=AMERICANEXPRESS&lf=2009" frameborder="0" scrolling="no"></iframe></div>
<form id="creditCardForm" method="post">
<div class="cvv-container ncss-row mb4-sm prl2-sm">
<div class="ncss-col-sm-12 prl0-sm u-va-t border-light-grey u-rounded">
<div class="ncss-row">
<label for="cvNumber" class="ncss-col-sm-8 text-color-grey pt2-sm pl6-sm pr2-sm pb2-sm u-va-m americanexpress-icn-launch">
0000
</label>
<div class="ncss-col-sm-4 u-va-m">
<div class="cc-container ncss-input-container error">
<input type="tel" id="cvNumber" tabindex="1" data-shortname="cvv" class="cc-input ncss-input pt2-sm pr4-sm pb2-sm pl4-sm u-align-center" "cvv"="" autocomplete="off" autocorrect="off" value="" maxlength="4">
</div>
</div>
</div>
</div>
</div>
<input type="hidden" id="parentDomain" value="https://www.nike.com">
<input type="hidden" id="enableIFrameBuster" value="true">
</form>
答案 0 :(得分:0)
Selenium with Python documentation UnOfficial
Hii那里
Selenium提供了以下方法来定位页面中的元素:
find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
这对你有用
self.driver.find_element_by_id('cvNumber').send_keys('0000')
答案 1 :(得分:0)
通常 CVV 字段位于<frame>
或模态对话框中。无论您根据 HTML 分享到发送密钥到CVV Box ,您必须引导 WebDriverWait ,并且可以使用以下代码行:
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='cc-input ncss-input pt2-sm pr4-sm pb2-sm pl4-sm u-align-center' and @id='cvNumber']"))).send_keys('0000')