python - 在 python 中使用 Selenium 完全加载运行命令而不等待页面
问题描述
我有 Selenium 的自动化,我想在打开链接后运行一些命令,但不等待加载页面,我想运行这些代码,即使页面没有完全加载,或者在页面加载时
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path=r"C:\Users\Gabri\anaconda3\chromedriver.exe")
wait: WebDriverWait = WebDriverWait(driver, 10)
driver.get('https://stackoverflow.com/')
# I want to run some commands in this lines, without wait the page load
...
# I did this wait just for print when the page completely load
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,
'body > header > div > div.-main.flex--item > a.-logo.js-gps-track > span')))
print('The page is completely load')
driver.quit()
我要运行的命令
...
与页面无关,这就是为什么我需要在不等待页面加载的情况下运行
解决方案
在不等待页面加载的情况下运行这些方法的最简单方法是在涉及driver.get('https://stackoverflow.com/')
方法之前运行它们
推荐阅读
- java - Elasticsearch 2.4 jvm.options 在 MacOS Mojave 上被忽略(自制安装)
- java - 数据库被锁定在 SQLite [Java]
- javascript - 处理 .htaccess 中的内容安全策略
- c++ - 在 Windows Server 2003 中注册 dll 时出现问题
- java - 谷歌语音到文本 Java SDK 如何将语音上下文添加到语音识别配置
- function - 如何通过按钮单击调用更新函数的代码
- javascript - 按顺序匹配字符串
- javascript - 嵌套的 forEach 循环 - 错误“forEach 不是函数”
- jboss7.x - 如何解决 org.springframework.web.util.NestedServletException:请求处理失败;使用 SAML
- sql - 更新语句给子查询错误的结果