簡體   English   中英

如何單擊 Selenium 和 Python 的特定按鈕?

[英]How to click the specific button with Selenium and Python?

我正在嘗試查找並單擊此按鈕。 但我總是面對“消息:無法找到元素:”

我嘗試了這個選項,但它對我沒有幫助:

首先: driver.find_element_by_xpath('//button[contains(text(), "CLAIM NOW.")]').click()

第二: driver.find_element_by_xpath('//button[@onclick="getClaim()"]').click()

第三: driver.find_element_by_css_selector('a.btn').click()

第四: driver.find_element_by_class_name('btn btn-lg btn-primary').click()

第五: driver.find_element_by_id('roll_button_container').click()

我也在使用time.sleep()所以它沒有時間問題

操作流程:單擊“立即索賠”后,將打開一個新選項卡。 但在上一個(我現在正在)中 - 我會得到積分。 我需要在項目上自動化這個

我幾乎完整的代碼(不能向您展示公司政策的所有內容):

from selenium  import webdriver
import time

driver = webdriver.Firefox (executable_path = "/Users/USER1/Downloads/AUTOMATION/geckodriver")

driver.get("https://LINK.net/")
time.sleep(3)
driver.find_element_by_xpath('/html/body/header/nav/div/div/ul/li[5]/a').click()
time.sleep(3)
element = driver.find_element_by_xpath('/html/body/div[3]/div/div/form/div[1]/input').send_keys("login")
time.sleep(3)
el2 = driver.find_element_by_xpath('/html/body/div[3]/div/div/form/div[2]/input').send_keys("password")
time.sleep(3)
driver.find_element_by_css_selector('#loginForm > div:nth-child(3) > button:nth-child(1)').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="test_button"]').click()
time.sleep(3)
#driver.find_element_by_xpath('//button[contains(text(), "CLAIM NOW!")]').click()
#driver.find_element_by_xpath('//button[@onclick="getClaim()"]').click()
#driver.find_element_by_class_name('btn btn-lg btn-primary').click()
#driver.find_element_by_id('roll_button_container').click()
driver.find_element_by_css_selector('a.btn').click()
time.sleep(3)
driver.quit()

while True:
  time.sleep(60 * 5)

有誰可以幫我正確點擊按鈕? 非常感謝。

按鈕

好的,看起來該頁面會將您重定向到一個充滿虛假廣告的頁面。 通過點擊鏈接,每次都會彈出一個隨機廣告。 或者,您可以使用 selenium 作為js運行getClaim

可以通過模擬按鈕按下來領取您的獎勵 - 運行按鈕將運行的 function - 僅運行 javascript 和 selenium

cmd = "getClaim()"
driver.execute_script(cmd)

正如您所說,我希望“可憐的印度人”可以幫助您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM