【发布时间】:2017-11-06 18:19:56
【问题描述】:
试图让脚本选择顶部的过滤器按钮,但似乎无法弄清楚如何输入 XPath。我相信这与它在单独的 iframe 中有关。
package chromebrowser;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class JavaClass {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Newfolder\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://mlvtwrew73.consilio.com/Relativity/");
driver.manage().window().maximize();
//Thread.sleep(5000); this can be used as a wait command before moving on to the next function
WebElement objWE;
Thread.sleep(9000);
// objWE = driver.findElement(By.linkText("User Status"));
// objWE.click();
driver.switchTo().defaultContent();
driver.findElement(By.xpath("id(\"ctl00_ctl00_itemList_FilterSwitch\")")).click();
// objWE = driver.findElement(By.id("1"));
// driver.close(); will be used to close the site once all testing completes
}
}
【问题讨论】:
-
如果在单独的frame中,需要switchTo()那个frame,然后再次执行xpath。
-
所以我将它添加到脚本中,但仍然出现同样的错误:driver.switchTo().frame("ListTemplateFrame"); driver.switchTo().defaultContent(); driver.findElement(By.xpath("id(\"ctl00_ctl00_itemList_FilterSwitch\")/img[1]")).click();
标签: java selenium iframe xpath