【发布时间】:2021-07-10 09:31:03
【问题描述】:
我在网站上有一个按钮,但即使我尝试了 find_element_by_xpath、id、class 等,它也没有点击。
按钮的元素代码是这样的
<button type="button" class="gpbutton" id="gtltranslate">Translate</button>
这是我的代码,它打开一个文件并将它们转换为另一个文件
import os
from tkinter import *
from tkinter import filedialog
import selenium
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium import webdriver
import contextlib as textmanager
PATH= "C:\Program Files (x86)\chromedrivers\chromedriver.exe"
driver= webdriver.Chrome(PATH)
eng=[]
driver.get("https://www.webtran.eu/finnish_english_translator/")
input1= driver.find_element_by_id("gtlsource")
output1= driver.find_element_by_id("gtlresults_body")
btn= driver.find_element_by_class_name("gpbutton")
lines= []
with open("sanat.txt", "r") as file:
for line in file:
line = line.strip() #or some other preprocessing
lines.append(line) #storing everything in memory!
k=0
while k != len(lines):
input1.send_keys(lines[k])
time.sleep(0.5)
btn.click()
time.sleep(0.5)
eng.append(output1)
input1.clear()
k=k+1
time.sleep(1)
这是错误
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button type="button" class="gpbutton" id="gtltranslate">...</button> is not clickable at point (534, 490). Other element would receive the click: <span id="cookieconsent:desc" class="cc-message">...</span>
(Session info: chrome=91.0.4472.124)
【问题讨论】:
-
我建议你使用 WebDriverWait 函数来等待按钮被加载并可以点击
标签: python python-3.x selenium selenium-webdriver selenium-chromedriver