在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);
}
}
答案 0 :(得分:0)
仔细检查您的定位器,对我来说,以下XPath expression正常工作:
//div[@role='button' and normalize-space()='Compose']
它通过role
div过滤attribute元素,并使用normalize-space() function忽略空格和换行符
答案 1 :(得分:0)
我的建议是等待页面上的JS载入后再调用您的点击。我将使用以下方法进行此操作-我已经在手机上输入了此信息,如果有任何错误,请先抱歉。
public static void waitForPageToLoad(){
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(new ExpectedCondition<Boolean>(){
@Override
public Boolean apply(WebDriver driver){
return ((JavascriptExecutor)driver).executeScript(“return document.readyState”).equals(“complete”);}});
`