[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);
	}

  

你可能感兴趣的:([Selenium] 针对下拉菜单出现之后又立马消失的问题,通过Javascript改变元素的可见属性)