gpt4 book ai didi

java - Selenium WebDriver——XPath

转载 作者:太空宇宙 更新时间:2023-11-04 10:58:29 24 4
gpt4 key购买 nike

enter image description here

尝试让脚本选择顶部的过滤器按钮,但似乎无法弄清楚如何输入 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

}

}

最佳答案

使用 ID 定位器——在这里更合适(并且比 XPath 更快):

WebDriverWait wait= new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.id("ct‌l00_ctl00_itemList_F‌​ilterSwitch")));
driver.findElement(By.id("ctl00_ctl00_itemList_FilterSwitch")).click();

关于java - Selenium WebDriver——XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com