【问题标题】:Selenium webdriver: Can not click on a button in a pop up windowSelenium webdriver:无法单击弹出窗口中的按钮
【发布时间】:2018-09-08 19:02:57
【问题描述】:

在一个网站上,我试图点击一个名为“同意”的按钮并继续接受弹出窗口中显示的 cookie,但它没有点击...

这是html:

'<div>'
 '<div class="mainContent" aria-hidden="false" style="">'
    '<div class="pdynamicbutton">'
       '<a class="call" tabindex="1" role="button">Agree and Proceed</a>'

我在eclipse中的代码:

'@When("^I click on agree terms and conditions$")
    public void i_click_on_agree_terms_and_conditions() throws Throwable {'

'driver.findElement(By.xpath("//a[@class='call']/span[text()='Agree And 
Proceed']")).click();'`

我还内置了一些等待页面加载(30 秒)的功能。

【问题讨论】:

  • 我没有看到 span 孩子。试试//a[@class='call' and text()='Agree And Proceed']
  • 不幸的是它不起作用。我正在尝试点击同意并在转到 www.kruidvat.nl URL 时继续
  • 如果将text()='Agree And Proceed'中的"And"替换为"and"会怎样?
  • @Sven152 您确定每次都显示“同意​​并继续”消息吗?我在 www.kruidvat.nl 中没有收到任何关于 cookie 的消息
  • 是的。在浏览器中尝试隐身模式。 “和”也不起作用..

标签: selenium selenium-webdriver


【解决方案1】:

试试 //div[@class='mainContent']//a[contains(text(),'同意并继续')]

【讨论】:

  • 出现以下消息:org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression '//div[@class='mainContent']//a[contains (text(),'Agree And Proceed'] 因为以下错误: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class='mainContent']//a[contains( text(),'Agree And Proceed']' 不是有效的 XPath 表达式。'(会话信息:chrome=68.0.3440.106)
  • 你把路径放在双引号内了吗?它给出了 SyntaxError。尝试稍微修改 XPath
  • 会不会是因为我的笔记本电脑上的其他语言设置导致元素没有点击?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-18
  • 1970-01-01
  • 2021-10-14
相关资源
最近更新 更多