久久久久久久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视频在线免费观看 | 国产免费一区二区三区网站免费 | 99pao成人国产永久免费视频 | 国产免费一区二区 | 亚洲精品视频免费观看 | 国产欧美一区二区三区久久人妖 | 在线不卡一区 | 日日操操操 | 伊人一区 | 91精品国产综合久久香蕉麻豆 | 成人激情视频免费在线观看 | 国产激情91久久精品导航 | 亚洲网在线 | 在线视频a| 亚洲视频免费在线观看 | 谁有毛片 | 中文二区 | 成人国产在线观看 | 黄色网页在线观看 | 欧美1级| 国产精品一区二区免费 | 日本不卡一区二区三区在线观看 | 天天操操操操操 | 特级黄一级播放 | 北条麻妃一区二区三区在线观看 | 日本三级电影在线观看视频 | 天天夜碰日日摸日日澡 | 一区二区三区视频 | 亚洲天堂久久 | 天堂综合网 | 免费观看一级特黄欧美大片 | julia中文字幕久久一区二区 | 亚洲人成人一区二区在线观看 | 国产在线不卡视频 | 欧美日韩国产一区二区三区 | 伊人久久在线 | 国产在线精品一区二区 | 久久亚洲一区二区三区四区 |