请你帮我调用每次都在变化的href值。以下是供您参考的代码:
<a href="http://click1.clickrouter.com/redirect?token=a2258079c24c4c50a56b6b1ffb75d6e2&url=https%3A//u2720269.ct.sendgrid.net/wf/click%3Fupn%3DRuyytLyMzocaRpUHe9Z1QCe0o5SY-2BbrKEnssVFEC2nFM466GSvGSbWIPZo2Xpeyn-2F0QAElxl7c7bwKXcdymgtcm9RjSv0ivZZXtv2n8DKYnWlKkQroF-2BEDfllIkFXTyS20elE5OuRKl3wPQBh0E76Nj-2BQArVjoxEfD4fUEVLUkI-3D_5SnvLCTBgVqPjimwaiavQTZsy6v0FmqoHbMtHV6MMfx-2FCs1eGI1d4Bexl3L2zftKx-2FvaNVM5Uwe7h0ZTAHWuyNOLa3UkvoB3WljrbHWRfL2LCArojXFquIo8ltK6-2BRTtQyTe7jpRGsBnxQUyyEhyT7KGbgdF0T-2BqZ01kZMoHzklNV-2BOkV6gSY0NZvlW0iq6LXowmHug1UsgSa4LTxTH0elpPaEGQhdEPe0zJsuoYSBQ-3D" target="_other" rel="nofollow">click here</a>
感谢。
答案 0 :(得分:1)
据我所知,测试用例需要href
(链接)属性值。所以代码可以通过这种方式编写:
String strLinkHref = driver.findElement(By.linkText("click here")).getAttribute("href");
或
String strLinkHref = driver.findElement(By.xpath("//a[text()='click here']")).getAttribute("href");
注意:这里可以存储在String中并打印。它每次都会动态获取链接。
如果需要打开测试用例,那么您可以使用:
driver.get(strLinkHref);
如果您需要移至TAB窗口,请使用以下代码:
String handle= driver.getWindowHandle();
System.out.println(handle);
// Click on the Button "New Message Window"
driver.findElement(By.name("New Message Window")).click();
// Store and Print the name of all the windows open
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
}
// Closing Pop Up window
driver.close();