我正在尝试单击跨度 n6 中的“新交易”链接,该跨度 n6 是跨度 n2 的子元素。我能够到达 n2,但它无法识别“n6”。
请帮助我是 Selenium WebDriver 的新手
在这里我发布了 html 和我的代码。
Trading
新的
贸易
贸易
探险家
我想点击新贸易
HTML 源代码 https://i.stack.imgur.com/KP3MA.png
我的代码一直持续到跨度“n2”:
driver.switchTo().frame(driver.findElement(By.name("treeFrame")));
WebElement allFormChildElements = driver.findElement(By.name("the_form"));
allFormChildElements.findElement(By.linkText("Trading")).click();
WebElement modalDialog = allFormChildElements.findElement(By.className("border"));
WebElement newmodalDialog = modalDialog.findElement(By.className("formScrollableMenuContent"));
System.out.println(newmodalDialog.findElements(By.tagName("a")).size()); // ans 5
WebElement newDialog= newmodalDialog.findElement(By.id("n2"));
System.out.println(newDialog.findElements(By.id("n3")).size()); // ans 0
使用图像我无法测试,但是,如果您能够到达该元素<span id="n2">
,从那里您可以使用以下 xpath 来单击带有文本“New Trade”的元素:
newDialog.findElement(By.xpath(".//span[@id='n6']/a[@name='A6' and text()='New Trade']")).click();
EDIT
如果 id 值发生变化,请尝试以下方式:
newDialog.findElement(By.xpath(".//span/a[@name='A6' and text()='New Trade']")).click();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)