久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

NoSuchElementException:消息:嘗試通過 Selenium 和 Pytho

NoSuchElementException: Message: Unable to locate element while trying to click on the button VISA through Selenium and Python(NoSuchElementException:消息:嘗試通過 Selenium 和 Python 單擊 VISA 按鈕時無法找到元素) - IT屋-程序
本文介紹了NoSuchElementException:消息:嘗試通過 Selenium 和 Python 單擊 VISA 按鈕時無法找到元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我無法單擊此按鈕在我的機器人上創建結帳.我想點擊圖片獲取另一個頁面.

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:

  • 無法定位使用 selenium python 的信用卡號元素
  • org.openqa.selenium.NoSuchElementException:嘗試通過 CssSelector 定位 card-fields-iframe 時返回的節點(null)不是 DOM 元素

因此,如果所需的元素在 <iframe> 內,那么您必須:

So if the the desired element is within an <iframe> so you have to:

  • 誘導 WebDriverWait 使所需的框架可用并切換到它.
  • 誘導 WebDriverWait 使所需的元素可點擊.
  • 您可以使用以下任一解決方案:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • 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,"http://iframe_xpath")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "http://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模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

    相關文檔推薦

    How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
    How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
    How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
    How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
    Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
    Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
    主站蜘蛛池模板: 中文字幕国产精品 | 四虎永久免费影院 | 欧美激情精品久久久久久变态 | 视频二区国产 | www.日本国产 | 亚洲欧美一区二区三区国产精品 | 99久久久久| 中文字幕在线第二页 | 中文字幕在线三区 | 天天拍天天草 | 粉嫩国产精品一区二区在线观看 | 欧美日韩在线精品 | 欧美视频中文字幕 | 久久久www成人免费无遮挡大片 | 久久r免费视频 | 女朋友的闺蜜3韩国三级 | 成人国产在线观看 | 欧美精品一区二区三区四区五区 | 中文字幕av在线播放 | 亚洲二区在线 | 欧美成人免费在线视频 | 97福利在线| 午夜爱爱网 | 福利视频亚洲 | 97综合在线| 国户精品久久久久久久久久久不卡 | www.日本在线观看 | 成人精品国产免费网站 | 亚洲一区二区精品视频 | 在线婷婷 | 伊人久久综合 | 亚洲综合色视频在线观看 | 亚洲播放一区 | 中文字幕日韩欧美 | av在线免费不卡 | 精品欧美乱码久久久久久1区2区 | 欧美精品国产精品 | 99爱视频| 91精品国产91久久久久久三级 | 国产成人91| 四虎最新地址 |