-1
我在需要自動化的應用程序之一中有棘手的情況 情況:用戶可以在一天內最多4次輸入應用程序中的數據。第五次當用戶按下輸入/提交按鈕,然後顯示交戰信息。硒網絡驅動程序需要的邏輯幫助
" div.container-fluid::before"
<div class="alert alert-warning fade in">Maximum entries reached."</div>"
這是HTML元素。 只有4次輸入後才能使用。直到第4次該元素不會出現
自動化的情況:首先檢查是否按下提交按鈕顯示錯誤消息。如果沒有顯示錯誤消息繼續for循環其他退出應用程序。 但劇本是失敗的,因爲如果沒有顯示錯誤消息,則是告訴 沒有這樣的元素:找不到元素「的XPath」 我嘗試以下,但似乎不工作:
wd = launchBrowser ("chrome");
wd.get(「website link 「);
wd.findElement(By.xpath(「.//*[@id='user_email']")).sendKeys(「UI」);
wd.findElement(By.xpath(".//*[@id='user_password']")).sendKeys("pwd」);
wd.findElement(By.xpath(".//*[@id='new_user']/div[3]/input")).click();
wd.findElement(By.xpath(".//*[contains(@class, 'btn btn-primary')]")).click(); //will navigate to data adding page.
wd.findElement(By.xpath("//*[@id=\"new_entry\"]/input[3]")).click();
// this is the submit button
Thread.sleep(1000);
String x = wd.findElement(By.xpath(" .//*[contains(@class, 'alert alert-warning fade in')]")).toString();
//This is the xpath which comes only if the data entered is already 4 times
if(x == null)
{
For(condition for 4 times to enter)
}
Else{
sysout(「Max number of times per is done」);
}
wd.quit();
}
你能做到的代碼塊'嘗試'catch'塊? –
你的引號看起來不正確,這甚至編譯?你有時使用''''和''''作爲'String's,但它應該是''''另外,什麼是'For(condition for 4 times to enter)',看起來不像是有效的Java。 – Zabuza
Try catch只有字符串x或從字符串x直到其他結尾...? – ABAJAVa