【问题标题】:Google chrome isn't allowing to automate joining a gmeet谷歌浏览器不允许自动加入 gmeet
【发布时间】:2021-11-25 20:48:30
【问题描述】:

我用 Python 编写了一个简单的程序,使用 selenium 自动导航到 gmeet 链接设置禁用摄像头/麦克风,然后单击立即加入按钮进入链接。下面是代码:

import string
import random
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

opt = Options()
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block

opt.add_experimental_option("prefs", { \
"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 1,
"profile.default_content_setting_values.geolocation": 1,
"profile.default_content_setting_values.notifications": 1
})
opt.add_experimental_option("useAutomationExtension", False)



driver = webdriver.Chrome(options = opt,executable_path = "path_to\\chromedriver.exe")

driver.get("https://meet.google.com/yiz-fdaz-tre")
time.sleep(5)
current_tab = driver.window_handles[0]
driver.switch_to_window(current_tab)
camera = driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[2]/div/div/div[1]')
camera.click()

mic = driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[1]/div/div/div/div[1]')
mic.click()

join = driver.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span')
join.click()

#time.sleep(5)
driver.close()

但是当我执行此脚本时,会打开一个不同的 chrome 窗口,其中显示 Chrome 正在由自动测试软件控制,并且 meet 不允许我加入会议。我什至无法从该 chrome 窗口手动加入会议,当我尝试登录时,它甚至不允许我登录,但是,如果我点击 google chrome 并重新打开一个窗口,一切正常美好的。当我的代码尝试打开/创建新的 Chrome 实例时,似乎会出现问题。我尝试降级到 93 版,但没有帮助。删除driver.close() 语句也没什么用。 有没有办法自动化这个过程,我的代码做错了吗?

【问题讨论】:

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


    【解决方案1】:

    Google 不喜欢自动浏览器。使用“未检测到的 Chromedriver”而不是 webdriver。

    通过 pip 安装:pip install undetected_chromedriver

    然后将webdriver 替换为undetected_chromedriver(或将UC 导入为 webdriver 以使其更容易)。我不太确定它是否仍然需要一个 webdriver 路径,因为它是使用 pip 安装的,但是这是您脚本的改编版本(也使用 driver.find_element(By.*, STRING):

    import string
    import random
    import undetected_chromedriver as webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    import time
    
    opt = Options()
    opt.add_argument("start-maximized")
    opt.add_argument("--disable-extensions")
    # Pass the argument 1 to allow and 2 to block
    
    opt.add_experimental_option("prefs", { \
    "profile.default_content_setting_values.media_stream_mic": 1,
    "profile.default_content_setting_values.media_stream_camera": 1,
    "profile.default_content_setting_values.geolocation": 1,
    "profile.default_content_setting_values.notifications": 1
    })
    
    driver = webdriver.Chrome(options = opt)
    
    driver.get("https://meet.google.com/yiz-fdaz-tre")
    time.sleep(5)
    current_tab = driver.window_handles[0]
    driver.switch_to_window(current_tab)
    camera = driver.find_element(By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[2]/div/div/div[1]')
    camera.click()
    
    mic = driver.find_element(By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[1]/div[1]/div/div[4]/div[1]/div/div/div/div[1]')
    mic.click()
    
    join = driver.find_element(By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[4]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span')
    join.click()
    
    #time.sleep(5)
    driver.close()
    

    不确定这是否有帮助,但到目前为止它对我有用。

    【讨论】:

    • 感谢您的回复,但它不起作用!!!
    猜你喜欢
    • 2021-05-27
    • 2011-04-28
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 2012-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多