Selenium WebDriver执行JavaScript脚本

1:处理日历控件

参考链接:https://www.cnblogs.com/tobecrazy/p/4206742.html

2:抓取文本信息

	/**
	 * 返回JS运行结果 title的
	 * */
	public String RetunJSValues(int row, int count,String fristTitlElement , String secondTitlElement){
		
		JavascriptExecutor js = driver.JSscript();
		String value = (String) js.executeScript("var text=document.getElementsByClassName('"+fristTitlElement+"')['"+row+"'].getElementsByTagName('"+secondTitlElement+"')['"+count+"'].innerText;return text");
		
		return value;
	}
	
	/**
	 * 返回JS长度datagrid-header-row
	 * */
	public int RetunJSValuesLenght(int row, String fristTitlElement , String secondTitlElement){
		
		JavascriptExecutor js = driver.JSscript();
		Long lenght = (Long) js.executeScript("var text=document.getElementsByClassName('"+fristTitlElement+"')['"+row+"'].getElementsByTagName('"+secondTitlElement+"').length;return text");
		
		int length1 = new Long(lenght).intValue();
		
		return length1;
	}

猜你喜欢

转载自blog.csdn.net/hujyhfwfh2/article/details/82789403