我无法点击元素
下面是我试图点击
的元素的属性<div class="btn-group bootstrap-select open" style="top: 246.983px; left: 537px; width: 220px; position: absolute;">
<div class="dropdown-menu open" style="overflow: hidden; min-height: 92px;">
<ul class="dropdown-menu inner" role="menu" style="overflow-y: auto; min-height: 80px;">
<li class="" data-original-index="0">
<li class="selected" data-original-index="1">
<a data-tokens="null" data-normalized-text="<span class="text">Editing Workflow</span>" tabindex="0">
我试过的代码是
**driver.findElement(By.xpath("//div[@class='dropdown-menu open']//span[contains(text(), 'Editing Workflow')]")).click();**
但它给出了例外如下 对应的StackTrace
:org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
然后我尝试了下面的javascriptExecutor代码
((JavascriptExecutor) Initialization.driver).executeScript("arguments[0].setAttribute('visibility', 'true');", this.wbElement);
但仍在提供以下异常
**2016-04-28 14:07:37 PM DEBUG [main] (ElmKeywordLib.java : 171) - Corresponding StackTrace :org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 45.18 seconds
Build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38'
System info: host: 'BLRKEC254298D', ip: '144.114.236.243', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_07'
Session ID: ee1d1fdd-7e46-4bba-abf3-837dcd54e54a
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.0}]**
请帮助解决这个问题。等待回复......
源代码:
public void selectTDWorkflowType() {
for (iflagCounter = 1;iflagCounter <= CommonFile.iStepsToExeCount && KeywordLibrary.isTestScenarioContinue;iflagCounter++){
fnDisplayStepCount();
if (CommonFile.strStepsToExecute.charAt(iflagCounter - 1)!='0'){
switch(CommonFile.iBpcExecutingCaseNum = iflagCounter){
case 1:
this.objKeywordLibrary.klWebElementClick(ObjectMap.OR_TD_BTN_WORKFLOW_TYPE_CREATEWF, ObjectMap.S_TD_BTN_WORKFLOW_TYPE_CREATEWF);
this.objKeywordLibrary.klSetAttriToMakeEleVisible(ObjectMap.OR_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF, ObjectMap.S_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF);
this.objKeywordLibrary.klWebElementClick(ObjectMap.OR_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF, ObjectMap.S_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF);
// this.objKeywordLibrary.klListSelectbyText(ObjectMap.S_TD_BTN_WORKFLOW_TYPE_CREATEWF, "WorkflowType", true);
break;
default:
LOGGER.warn(StringConstants.STRSTEPEXEINFO);
break;
}
}
else
LOGGER.info(StringConstants.STRBPCEXEINFO);
}
}
public void klSetAttriToMakeEleVisible(String strFindProperty, String strName)
{
try {
if(klIsElementPresentNoReport(strFindProperty)){
this.wbElement = Initialization.driver.findElement(By.xpath(strFindProperty));
((JavascriptExecutor) Initialization.driver).executeScript("arguments[0].setAttribute('visibility', 'true');", this.wbElement);
// this.wbElement.click();
((JavascriptExecutor) Initialization.driver).executeScript("arguments[0].click;", this.wbElement);
this.wbElement.click();
public void klSetAttriToMakeEleVisible(String strFindProperty, String strName)
{
try {
if(klIsElementPresentNoReport(strFindProperty)){
this.wbElement = Initialization.driver.findElement(By.xpath(strFindProperty));
((JavascriptExecutor) Initialization.driver).executeScript("arguments[0].setAttribute('visibility', 'true');", this.wbElement);
// this.wbElement.click();
((JavascriptExecutor) Initialization.driver).executeScript("arguments[0].click;", this.wbElement);
this.wbElement.click();
}catch (NoSuchElementException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",String.format(StringConstants.STRCLRELEEXPECTED,strName), StringConstants.STRNOSUCHELEEXCEP.concat(StringConstants.STRCHKLOG));
}catch (UnreachableBrowserException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",String.format(StringConstants.STRCLRELEEXPECTED,strName), StringConstants.STRUNRECBROWEXCEP);
RecoveryScn.recUnReachableTestScnExitTrue();
}catch (WebDriverException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",String.format(StringConstants.STRCLRELEEXPECTED,strName), StringConstants.STRWEBDRVEXCEP);
}
}
public boolean klWebElementClick(String strFindProperty, String strName)
{
boolean bReturnStatus = false;
try {
for(int i=0;i<=2;i++)
{
// try{
if (klIsElementPresentNoReport(strFindProperty)){
this.wbElement.isDisplayed();
System.out.println("Is element is displayed/visible: "+this.wbElement.isDisplayed());
this.wbElement.click();
klWait(1000);
ReportingFunctionsXml.fnSetReportBPCStepStatus(true, strName,
"", String.format(StringConstants.STRCLKELEEXPECTED,strName), String.format(StringConstants.STRCLKELESUCCS,strName));
this.wbElement=null;
bReturnStatus = true;
} else
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName,
"", String.format(StringConstants.STRCLKELEEXPECTED,strName), String.format(StringConstants.STRCLKELEFAILURE,strName));
break;
}
}catch (NoSuchElementException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
LOGGER.error(StringConstants.STRNOSUCHELEEXCEP);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",
String.format(StringConstants.STRCLKELEEXPECTED,strName), StringConstants.STRNOSUCHELEEXCEP);
}catch (UnreachableBrowserException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
LOGGER.error(StringConstants.STRUNRECBROWEXCEP);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",
String.format(StringConstants.STRCLKELEEXPECTED,strName), StringConstants.STRUNRECBROWEXCEP);
RecoveryScn.recUnReachableTestScnExitTrue();
}catch (WebDriverException e) {
LOGGER.debug(StringConstants.STRSTACKTRACE+ e);
LOGGER.error("\t"+StringConstants.STRWEBDRVEXCEP);
ReportingFunctionsXml.fnSetReportBPCStepStatus(false, strName, "",
String.format(StringConstants.STRCLKELEEXPECTED,strName), StringConstants.STRWEBDRVEXCEP);
}return bReturnStatus;
}
Objects (Xpath and Description):
**public static final String OR_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF= "//div[@class='dropdown-menu open']//span[contains(text(), 'Editing Workflow')]";
public static final String S_TD_BTN_WORKFLOWTYPE_EDITINGL_CREATEWF= "TD_Editing Workflow option in Workflow Type drop-list of Create Workflow screen";**
由于 Shantaveer