在运行我的测试铬页时,selenium有问题(一些表单被破坏,字段位置不正确,因此无法填充数据)
应该像这样打开

但要这样做:

如果有类似版本的色度驱动器和铬:
current google-chrome version is 99.0.4844
Get LATEST chromedriver version for 99.0.4844 google-chrome
Driver [C:\Users\yerba\.wdm\drivers\chromedriver\win32\99.0.4844.51\chromedriver.exe] found in cache我的代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
url = "https://opi.dfo.kz/p/ru/archive-publication/corporative-events-2020-14-07"
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get(url)
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='logic-group-condition' and .//span[@field-name='tbOpiActiveRevisions_flBin']]"))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@class='editor-text']"))).send_keys("010140000143")发布于 2022-03-27 12:43:34
根据Selenium文档,visibility_of_element_located()希望检查页面的DOM中是否存在一个元素,并且是可见的。可见性意味着元素不仅显示,而且具有大于0的高度和宽度。但是,这个条件并不意味着元素是可点击的和可插入的。
解决方案
理想情况下,要调用click()和send_keys()而不是,需要为引入WebDriverWait,如下所示:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='logic-group-condition' and .//span[@field-name='tbOpiActiveRevisions_flBin']]"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='editor-text']"))).send_keys("010140000143")https://stackoverflow.com/questions/71635577
复制相似问题