问题描述
打开,因为所需元素位于< 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:
- Ways to deal with #document under iframe
- Is it possible to switch to an element in a frame without using driver.switchTo().frame("frameName") in Selenium Webdriver Java?
这篇关于无法使用带有Java客户端的Selenium Webdriver单击输入类型提交导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!