首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Selenium和Python expected_conditions作为visibility_of_element_located()进行交互时,网页UI元素和表单会中断

使用Selenium和Python expected_conditions作为visibility_of_element_located()进行交互时,网页UI元素和表单会中断
EN

Stack Overflow用户
提问于 2022-03-27 10:37:35
回答 1查看 109关注 0票数 0

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

应该像这样打开

但要这样做:

如果有类似版本的色度驱动器和铬:

代码语言:javascript
复制
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

我的代码:

代码语言:javascript
复制
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")
EN

回答 1

Stack Overflow用户

发布于 2022-03-27 12:43:34

根据Selenium文档,visibility_of_element_located()希望检查页面的DOM中是否存在一个元素,并且是可见的。可见性意味着元素不仅显示,而且具有大于0的高度和宽度。但是,这个条件并不意味着元素是可点击的可插入的

解决方案

理想情况下,要调用click()send_keys()而不是,需要为引入WebDriverWait,如下所示:

代码语言:javascript
复制
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")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71635577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档