首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium WebDriver -- XPath

Selenium WebDriver -- XPath
EN

Stack Overflow用户
提问于 2017-11-07 02:19:56
回答 4查看 121关注 0票数 1

尝试让脚本选择顶部的filter按钮,但似乎不知道如何输入XPath。我相信这与它在一个单独的iframe中有关。

代码语言:javascript
复制
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

	}

}

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-11-07 03:02:47

使用ID定位器--它在这里更合适(而且比XPath更快):

代码语言:javascript
复制
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();
票数 0
EN

Stack Overflow用户

发布于 2017-11-07 02:28:46

关于你的问题,我需要更多的澄清。据我所知,我认为你需要一个滤镜图像的XPath的要求。如果我是对的,试试这个:

代码语言:javascript
复制
//div[@class='actionCellContainer']//a/img[@class='itemListActionImage']
票数 0
EN

Stack Overflow用户

发布于 2017-11-07 02:49:23

看起来你传入的XPath不正确。试试这个:

代码语言:javascript
复制
driver.findElement(By.xpath("//a[@id='ctl00_ctl00_itemList_FilterSwitch']")).click();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47143280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档