python selenium会一直刷新,直到找到项目(Chromedriver)

python selenium会一直刷新,直到找到项目(Chromedriver),python,html,google-chrome,selenium,selenium-chromedriver,Python,Html,Google Chrome,Selenium,Selenium Chromedriver,我正在尝试使用selenium实现Python脚本的功能,以不断刷新当前chromepage,直到找到生成driver.find\u element\u by\u partial\u link\u text(“Schott”)的特定项 我在想: while not driver.find_element_by_partial_link_text("Schott"): driver.refresh driver.find_element_by_partial_link_text("Scho

我正在尝试使用selenium实现Python脚本的功能,以不断刷新当前chromepage,直到找到生成
driver.find\u element\u by\u partial\u link\u text(“Schott”)
的特定项

我在想:

while not driver.find_element_by_partial_link_text("Schott"):
    driver.refresh
driver.find_element_by_partial_link_text("Schott").click()
但是,它似乎是函数
驱动程序。通过部分链接文本(“Schott”)查找元素
不是满足需要的方法。请问,我还有其他方法可以做到这一点吗


顺便说一句,目前我正在使用driver.get(url)打开网页,但我想知道如何在已打开的现有网页上运行脚本?

使用
find\u element\u…
如果找不到元素,将引发
NoSuchElementExeception
。因为我不知道你在哪个网站上运行这个,我不知道最好的做法是什么。但是,如果只是刷新页面以检查元素,则可以尝试以下操作:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

driver.Firefox()  # or whatever webdriver you're using
driver.get(url that you are going to)
while True:
    try:
        driver.find_element_by_partial_link_text("Schott"):
    except NoSuchElementException:
        driver.refresh
    else:
        driver.find_element_by_partial_link_text("Schott").click()
        break

还有,在同一个chrome页面下是否有打开新标签的功能?喜欢“Control+T”命令,然后在新选项卡上执行类似操作?@EdisonHua您使用的浏览器是什么?编辑:无需担心。。。你的标签上写着chrome。给我一秒钟在chrome上打开一个新标签,我能让它工作的唯一方法是使用
驱动程序。执行脚本('window.open(“about:blank”,“about:blank”)))
,但是你必须使用
驱动程序将焦点切换到
窗口句柄
。切换到窗口(driver.window\u句柄[-1])
by window.open,如果我想开门,我该怎么办?我尝试了driver.execute_脚本('window.open(“),但失败:(@EdisonHua包括完整的url,包括http://....
driver.execute\u脚本('window.open('http://www.google.com“,”空白“;”)