【问题标题】:Selenium Runs Chrome Profile But Not Rest Of ScriptSelenium 运行 Chrome 配置文件,但不运行其余脚本
【发布时间】:2020-06-15 00:24:46
【问题描述】:
#Required Boundaries
from selenium import webdriver
import time

#Opens Chrome Profile
options = webdriver.ChromeOptions()
options.add_argument("/Users/paolamohan/Library/Application Support/Google/Chrome/Default")
driver = webdriver.Chrome(executable_path=r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",options=options)
time.sleep(2)


#Gmail
Gmail = driver.find_element_by_xpath('//*[@id="gb"]/div[2]/div[3]/div[1]/div/div[1]/a')
Gmail.click()

这是我的代码。我想出了如何让 Webdriver 使用我的 Chrome 配置文件打开 Chrome,但现在我在它执行后无法运行其他任何东西。对于这个简单的例子,我只想让脚本点击谷歌主页右上角的“Gmail”小图标

我是 Python 新手,所以任何编写的代码都会非常有用! 谢谢

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver


    【解决方案1】:

    在单击按钮之前,Selenium 需要打开带有driver.get(url) 的页面。

    所以你这样做:

    #Required Boundaries
    from selenium import webdriver
    import time
    
    #Opens Chrome Profile
    options = webdriver.ChromeOptions()
    options.add_argument("/Users/paolamohan/Library/Application Support/Google/Chrome/Default")
    driver = webdriver.Chrome(executable_path=r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",options=options)
    time.sleep(2)
    
    #Access Site
    url = "https://google.de"
    driver.get(url)
    
    #Gmail
    Gmail = driver.find_element_by_xpath('//*[@id="gbw"]/div/div/div[1]/div[1]/a')
    Gmail.click()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 2014-07-29
      • 2016-09-07
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多