我正在尝试单击此网页上的“联系我们”链接。当我使用xpath,cssselector,linktext中的findelement选项时,出现此错误。一些解决方案提出以下建议:我右键单击该页面,然后单击“查看页面源”并搜索iFrame。但是,我找不到任何。所以我不认为这是switchto.frame()问题?我还尝试从xpath中删除“ *”,但这也不起作用。
我还添加了Thread.sleep(),但这还没有解决问题?
Java中的Selenium代码:
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"/Chromedriver/ChromeDriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://my.voya.com/voyasso/index.html?domain=voyaretirement.voya.com#/login-pweb");
String window1 = driver.getWindowHandle();
System.out.println("The Window Handle is " +window1);
// driver.switchTo().frame(window1);
WebElement link = driver.findElement(By.xpath("//*[@id=\"header-info\"]/a"));
link.click();
Thread.sleep(8000);
String window2 = driver.getWindowHandle();
System.out.println("The Window Handle is " +window2);
}
}
这是我要单击“联系我们”以在另一个窗口中打开的html代码。
<a class="b au-target" target="_blank" au-target-id="5" href="https://voyaretirement.voya.com/einfo/contactus.aspx?domain=voyaretirement.voya.com&cl=INGWIN&page=prelogin&pl=dummy">Contact Us</a>
这是来自控制台的错误消息
线程“主” org.openqa.selenium.NoSuchElementException中的异常:没有这样的元素:无法找到元素:{“ method”:“ xpath”,“ selector”:“ // * [@ id =” header-info“] /一种”}
解决此问题的最简单方法是添加一个等待元素可单击的行为,然后单击它。
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='header-info']/a"))).click();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句