我无法单击此按钮在我的机器人上创建结帐.我想点击图片获取另一个页面.
I can't click on this button to create a checkout on my bot. I want to click the image to get another page.
<label for="VISA" class="choiceLabel">
<input type="radio" class="visuallyhidden" name="cardTypeRadio" id="VISA" value="VISA" title="VISA" onclick="validateAndSubmit('VISA');">
<span class="imgElt xh-highlight" onclick="validateAndSubmit('VISA');">
<img src="/static/2.15.0.1/images/type-carte/visa.png" alt="VISA" title="Visa">
</span>
<span class="txtElt">Visa</span>
</label>
这是我的代码:
try:
check = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID,"VISA" )))
print ("Page is ready!")
visa = driver.find_elements_by_xpath("label[@class='choiceLabel'][4]")
visa.click()
except TimeoutException:
print ("Loading took too much time!")
return check
我收到此错误:
File "C:UsersxAppDataLocalProgramsPythonPython37lib hreading.py", line 917, in _bootstrap_inner
self.run()
File "C:UsersxAppDataLocalProgramsPythonPython37lib hreading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:/Users/pietro/Documents/monitor/x/bot.py", line 48, in all
visa = driver.find_element_by_xpath("label[@class='choiceLabel'][4]")
File "C:UsersxAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:UsersxAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebdriver.py", line 978, in find_element
'value': value})['value']
File "C:UsersxAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:UsersxAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: label[@class='choiceLabel'][4]
在我的机器人上创建结帐的按钮 似乎是一个 信用卡 相关领域,并且在历史上信用卡相关字段位于<iframe>中.
The button to create a checkout on my bot seems to be a Credit Card related field and historically Credit Card related fields resides within <iframe>.
您可以在以下位置找到一些相关讨论:
You can find a couple of relevant discussions in:
因此,如果所需的元素在 <iframe> 内,那么您必须:
So if the the desired element is within an <iframe> so you have to:
您可以使用以下任一解决方案:
You can use either of the following solutions:
使用 CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe_css_selector")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='VISA']"))).click()
使用 XPATH:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe_xpath")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='VISA']"))).click()
注意:您必须添加以下导入:
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
这篇关于NoSuchElementException:消息:尝试通过 Selenium 和 Python 单击 VISA 按钮时无法找到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在python中的感兴趣区域周围绘制一个矩形How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
如何使用 OpenCV 检测和跟踪人员?How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
如何在图像的多个矩形边界框中应用阈值?How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
如何下载 Coco Dataset 的特定部分?How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
根据文本方向检测图像方向角度Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
使用 Opencv 检测图像中矩形的中心和角度Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)