[Selenium] 針對下拉菜單出現以後又立馬消失的問題,經過Javascript改變元素的可見屬性

public void clickDateDropDownButton() {
		SeleniumUtil.jsClick(driver, page.getDateDropdownButtonOfInvPolicyDialog());
		WebElement dropDown = page.getDropdownListOfDateInInvPolicyDialog();
		
		String oldStyle =dropDown.getAttribute("style");
		logger.info("The old style is : " + oldStyle);
		
		String newStyle="";
		if(oldStyle.contains("display")){
			newStyle = oldStyle.split("display")[0];
		}
		else{
			newStyle = oldStyle+" display: none;";
		}
		
		String javaScript = "return jQuery(arguments[0]).attr('style','"+newStyle+"');";
		((JavascriptExecutor) driver).executeScript(javaScript, dropDown);
		
		logger.info("The new style is : " + newStyle);
	}
相關文章
相關標籤/搜索