登录成功使用gmail后,我无法单击“撰写邮件”按钮。它给出NoSuchElementException错误。
Executemail.java
public void clickin(String objectname) throws Exception{
WebDriverWait wait=new WebDriverWait(driver,20);
WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(prop.getProperty(objectname))));
element.click();
}
keyword.java
if(a.get(i).equals("clickin")) {
String Keyword = (String)a.get(i);
String data = (String)a.get(i+1);
String objectname = (String)a.get(i+2);
String runmode = (String)a.get(i+3);
System.out.println(Keyword);
System.out.println(data);
System.out.println(objectname);
System.out.println(runmode);
if(runmode.equals("Yes")) {
key.clickin(objectname);
}
}
enter image description here
最佳答案
仔细检查您的定位器,对我来说,以下XPath expression正常工作:
//div[@role='button' and normalize-space()='Compose']
它通过
role
div过滤attribute元素,并使用normalize-space() function忽略空格和换行符