无法使用带有Java客户端的Selenium Webdriver单击输入类型提交导航 [英] Cannot click input type submit navgation using Selenium Webdriver with java client

查看:94
本文介绍了无法使用带有Java客户端的Selenium Webdriver单击输入类型提交导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开,因为所需元素位于< iframe> ,因此您必须:



  • 为所需的 frameToBeAVailableAndSwitchToIt引入 WebDriverWait

  • 为所需的 elementToBeClickable 诱导 WebDriverWait

  • 您可以使用以下定位器策略

    • 使用 cssSelector

        driver.get(" h ttp://www.canadapostsurvey.ca/); 
      new WebDriverWait(driver,10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector( frame#mainFrame))));
      新的WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.cssSelector( input [value ='Next']))))。click();



    • 使用 xpath

        driver.get( http://www.canadapostsurvey.ca/); 
      新的WebDriverWait(driver,10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath( // frame [@ id =‘mainFrame’]))));
      new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath( // input [@ value ='Next']))))。click();








参考


您可以在以下位置找到一些相关的讨论:



Open http://www.canadapostsurvey.ca/, try to locate the "Next" navigation button click or submit it using xpath or cssselector or other method but does not work. (updates: found an alternative solution not using any find element methods but would like to hear from others)

Have tried different locator properties but none of it works, any ideas?

new  WebDriverWait(driver,5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"nav-controls\"]/input")));
driver.findElement(By.xpath("//*[@id=\"nav-controls\"]/input")).click();`

html code:

<div id="nav-controls" class="btn-container nav-center">
<input type="submit" name="_NNext" class="mrNext" style="" value="Next" alt="Next">
</div>

Screenshot of the page:

解决方案

To click() within the element with placeholder as Choose username within the url https://mail.protonmail.com/create/new?language=en, as the the desired element is within a <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:
    • Using cssSelector:

      driver.get("http://www.canadapostsurvey.ca/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame#mainFrame")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[value='Next']"))).click();
      

    • Using xpath:

      driver.get("http://www.canadapostsurvey.ca/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@id='mainFrame']")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='Next']"))).click();
      


Reference

You can find a couple of relevant discussions in:

这篇关于无法使用带有Java客户端的Selenium Webdriver单击输入类型提交导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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