如何使用 Selenium 和 Python 在 https://meet.google.com 中单击“请求加入"按钮? [英] How to click on the Ask to join button within https://meet.google.com using Selenium and Python?

查看:199
本文介绍了如何使用 Selenium 和 Python 在 https://meet.google.com 中单击“请求加入"按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试单击 google meet 链接中的请求加入按钮(使用我现有的 Google Chrome 个人资料).这是代码:

I am trying to click the Ask to join button in a google meet link(using my existing Google Chrome profile).This is the code:

options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\\Users\\Pranil.DESKTOP-TLQKP4G.000\\AppData\\Local\\Google\\Chrome\\User Data")
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
delay = 15
browser.get('https://meet.google.com/tws-kcie-aox')
ignored_exceptions=(NoSuchElementException,StaleElementReferenceException,)
time.sleep(5)
join_butt = WebDriverWait(browser, delay ,ignored_exceptions=ignored_exceptions).until(EC.presence_of_element_located((By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div[5]/div[3]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div')))
join_butt.click()
print(join_butt.text)#this prints Ask to join

但是没有点击加入按钮.按钮上最奇怪的部分要求加入"文本确实打印在最后一行.这意味着硒已经到达正确的按钮.但是为什么它不点击按钮?

But the join button is not getting clicked. The most weird part 'Ask to join' text on the button does get printed in the last line. This means that selenium has reached the correct button. But still why does it not click the button?

根据@Alin Stelian 的回答,我更新了代码如下:

According to an answer by @Alin Stelian I updated the code as follows:

browser.get('https://meet.google.com/hst-cfck-kee')
browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'd')
join_butt = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
join_butt.click()
print(join_butt)
print(join_butt.text)

这确实有效,因为两个打印语句都有效...但是按钮没有被点击.这里出了什么问题?

This does work as both the print statements work...But the button isn't getting clicked. What is going wrong over here?

推荐答案

对于进一步的自动化项目 - 在以编程方式生成值时避免通过 id 查找元素 - 它不会帮助您.此外,长 xpath 对您的项目性能不利.

For further automating projects - avoid finding elements by id when the value is generated programmatically - it will not help you. Also, long xpaths is bad for your project performance.

定位器的性能等级为 ->ID、CSS、XPATH.

The performance level of locators is -> ID, CSS, XPATH.

join_butt = WebDriverWait(browser, delay ,ignored_exceptions=ignored_exceptions).until(EC.presence_of_element_located((By.XPATH, '//span[contains(text(),'Ask to join')]')))

稍后编辑下次不要忽略异常 - 它会帮助你看到你的错误语法,我自己测试了下面的代码.

later edit next time don't ignore exceptions - it will help you to see your error syntax, I tested myself the below code.

join_butt = WebDriverWait(browser, delay).until(
    EC.presence_of_element_located((By.XPATH, "//span[contains(text(),'Ask to join')]")))
driver.execute_script("arguments[0].click();", join_butt)

如果 Chrome 浏览器不允许您登录 - 这是一个技巧

If the chrome browser doesn't allow you to log in - here is a trick

  1. 运行你的代码
  2. 在该浏览器中转到 StackOverflow
  3. 使用您的帐户登录
  4. 退出浏览器
  5. 再次运行您的代码 - 现在您将自动登录您的 Google 帐户.

这篇关于如何使用 Selenium 和 Python 在 https://meet.google.com 中单击“请求加入"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆