python - 使用硒将数据插入标签
问题描述
我有一个页面,我无法单击带有 selenium 的按钮,在单击按钮之前,html 看起来像这样:
有一种方法可以将该值插入到 html 标记中,以便在案例按钮中获得我想要的元素的可见性。我尝试使用 WebDriverWait 和 ActionChains 但没有成功。
我执行javascript代码:
driver.execute_script('document.getElementsByTagName("html")[0].setAttribute("data-whatelement", "button")')
driver.execute_script('document.getElementsByTagName("html")[0].setAttribute("data-whatclasses", "Button__StyledButton-iESSlv,dJJJCD Button-dtUzzq kHUYTy")')
而且按钮元素仍然不可见。我怎样才能让元素尝试使用 EC 等待和操作链。它是否超时异常。任何建议。
解决方案
使用execute_script
您可以运行 javascript 并随意操作 DOM。请参阅:使用 Python 在 Selenium 中运行 javascript
因此,例如(我不完全确定您需要做什么才能获得元素的可见性),将data-inq-observer
属性重新插入body
标签:
driver.execute_script('document.getElementByTagName("body").setAttribute("data-inq-observer", "1")')
推荐阅读
- c++ - 使用字符串流更新变量
- ios - Xcode iOS项目:运行调试构建时控制台日志开始处的“fopen failed”和“Invalidating cache...”是什么意思?
- c# - 获取异常读取异步错误:“句柄无效。” 用于 xamarin 形式的 BLE
- python - 使用 for 循环创建时间列表
- c# - 访问命名空间内的类 Unity C# 寻路
- sql - SQL 正则表达式
- android - StrictMode 政策违规:我的应用程序中的 android.os.strictmode.LeakedClosableViolation?
- three.js - 是否有可能使这个 GPGPU 水示例适用于不同形状(矩形、回旋镖)的平面?
- python - “播放”未定义 - Pylance (reportUndefinedVariable)
- angular - 获取默认选择的Angular路由器链接项