【问题标题】:cannot click on Agree & Continue button in Paypal CheckOut using Selenium无法使用 Selenium 在 Paypal CheckOut 中单击“同意并继续”按钮
【发布时间】:2017-10-05 21:44:41
【问题描述】:

我正在使用 selenium 来测试零售网站。到达结帐页面后,我选择了 Paypal 选项,其中沙盒 URL 正在打开。

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-07L974777B231831F#/checkout/login

我可以输入用户名和密码,点击登录按钮。

之后我被重定向到“同意并继续”页面。我无法执行任何操作的地方。

我可以清楚地看到下面的按钮属性

我已尝试以下代码,但无法执行任何操作。

WebElement AgreeandContinue= driver.findElement(By.tagName("input"));
AgreeandContinue.click();

【问题讨论】:

    标签: java selenium selenium-webdriver


    【解决方案1】:

    您可能在同一页面中有许多输入元素。尝试按类或 id 选择呢?

    WebElement AgreeandContinue= driver.findElement(By.ByClassName('btn'));
    

    WebElement AgreeandContinue= driver.findElement(By.ByClassName('continueButton'));
    

    然后使用submit() 而不是click() 因为元素是“提交”类型`

    仅供参考:https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html

    【讨论】:

      【解决方案2】:

      看起来按钮定义了一个 id,所以这将是最好的定位器:driver.findElement(By.id("confirmButtonTop));

      如果这不起作用,那么您可能需要添加一些等待按钮才能单击。

      如果这仍然不起作用,那么与许多商业工具一样,按钮实际上可能位于不同的 iframe 中。在 html 中进一步查看以确认是否是这种情况(它将有一个 iframe 标记)。如果是这种情况,那么您必须先切换到 iframe,然后再单击按钮:driver.switchTo().frame(...)How to identify and switch to the frame in selenium webdriver when frame does not have id

      【讨论】:

        【解决方案3】:

        如果我们查看HTML,您提供了WebElement value Agree & Continue<input> 标记内。所以我们要构造一个唯一的css或者xpath来识别WebElement,如下:

        1. cssSelector

          WebElement AgreeandContinue= driver.findElement(By.cssSelector("input#confirmButtonTop"));
          

        1. xpath

          WebElement AgreeandContinue= driver.findElement(By.xpath("//input[@id='confirmButtonTop']"));
          

        【讨论】:

          【解决方案4】:

          用ID试试,如果不是你可以用其他定位器试试,我建议你必须使用xpaths:

          driver.findElement(By.xpath("//input[contains(@id,'confirmButtonTop')]")).click();
          

          driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();
          

          我还建议您可以使用等待直到元素可点击或可见

          WebDriverWait wait = new WebDriverWait(driver, 15);
          wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(@id,'confirmButtonTop')]")));
          driver.findElement(By.xpath("//input[contains(@id,'confirmButtonTop')]")).click();
          

          WebDriverWait wait = new WebDriverWait(driver, 15);
          wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[contains(@id,'confirmButtonTop')]")));
          driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();
          

          【讨论】:

            猜你喜欢
            • 2018-09-01
            • 2021-01-08
            • 2014-01-04
            • 2020-12-15
            • 1970-01-01
            • 2019-09-16
            • 2014-06-27
            • 1970-01-01
            • 2021-04-09
            相关资源
            最近更新 更多