使用 selenium for python 自动点击来自 example@gmail.com 的电子邮件
Use selenium for python to automatically click on email from example@gmail.com
我想自动点击来自 example@gmail.com 的电子邮件,我知道只有一封来自那个人的电子邮件,所以两封相同的电子邮件不会有问题。
我已经尝试找到电子邮件的 XPath 并且工作正常。但是当我尝试用 webdriver.find_element_by_xpath("XPath of the email").click()
单击它时,XPath 不可单击。
据我所知,我只能指定 <tr></tr>
我想点击的那一行 webdriver.find element_by_xpath("XPath of row").click()
然后它点击了它。
是否可以通过某种方式单击包含特定电子邮件的行?
我认为您的语法不正确,
这应该是
webdriver.find_element_by_xpath("XPath of the email").click()
像这样
webdriver.findElement(By.xpath("xpath of the email']")).click();
如果id相同,只使用find_element_by_id()
方法而不是xpath应该也足够了。
element = firefox.find_element_by_id("the_id")#if the id is the same
element.click()
您可以使用下面的 xpath 获取包含 example@gmail.com
span 的行。
选项 1:
//span[@email='example@gmail.com']/ancestor::tr[@role='row']
选项 2:
//tr[@role='row'][.//span[@email='example@gmail.com']]
截图:
我想自动点击来自 example@gmail.com 的电子邮件,我知道只有一封来自那个人的电子邮件,所以两封相同的电子邮件不会有问题。
我已经尝试找到电子邮件的 XPath 并且工作正常。但是当我尝试用 webdriver.find_element_by_xpath("XPath of the email").click()
单击它时,XPath 不可单击。
据我所知,我只能指定 <tr></tr>
我想点击的那一行 webdriver.find element_by_xpath("XPath of row").click()
然后它点击了它。
是否可以通过某种方式单击包含特定电子邮件的行?
我认为您的语法不正确, 这应该是
webdriver.find_element_by_xpath("XPath of the email").click()
像这样
webdriver.findElement(By.xpath("xpath of the email']")).click();
如果id相同,只使用find_element_by_id()
方法而不是xpath应该也足够了。
element = firefox.find_element_by_id("the_id")#if the id is the same
element.click()
您可以使用下面的 xpath 获取包含 example@gmail.com
span 的行。
选项 1:
//span[@email='example@gmail.com']/ancestor::tr[@role='row']
选项 2:
//tr[@role='row'][.//span[@email='example@gmail.com']]
截图: