1
我已經創建了一個腳本,我想通過它來取消發佈一個元素,然後刪除頁面上的所有列表。這兩個選項都是未發佈和刪除的。看起來,當我們點擊圖標(所以這兩個元素都顯示,當我們點擊圖標)使用硒時刪除按鈕卡住,但通常它工作
現在,當我要點擊刪除按鈕,然後彈出一個授權應該出現,但這不會發生,當我使用硒,而當我正常使用網站(沒有硒),那麼它工作正常。
每行都有很多未發佈和刪除按鈕。
我也試圖與JavascriptExecutor和操作
我的代碼: -
List<WebElement> unpublishlink1 = d.findElements(By.cssSelector("a.action-publish.action_profile_unpublish"));
List<WebElement> deletelink1 = d.findElements(By.cssSelector("em.icon16.icon16-delete"));
WebElement deleted = null;
for (WebElement deletelink: deletelink1) {
WebElement cogiconlink = d.findElement(By.className("device-action-menu-arrow"));
cogiconlink.click();
deleted=deletelink;
}
for (WebElement unpublishlink: unpublishlink1) {
while (unpublishlink.isDisplayed() || deleted.isDisplayed() ) {
if (unpublishlink.isDisplayed()) {
unpublishPopup(d,unpublishlink, deleted);
} else {
deleteAlert(d,deleted);
}
}
}
}
public void unpublishPopup(WebDriver d,WebElement unpublishlink,WebElement deleted)
{
unpublishlink.click();
d.findElement(By.id("Unpublish_Profile"));
d.findElement(By.id("UnpublishProfileReason")).sendKeys("lish");
d.findElement(By.id("UnpublishProfilePassword")).sendKeys("@123");
d.findElement(By.id("UnpublishProfileYes")).click();
d.manage().timeouts().implicitlyWait(60000, TimeUnit.MILLISECONDS);
d.get(d.getCurrentUrl());
deleteAlert(d, deleted);
}
public void deleteAlert(WebDriver d,WebElement deleted)
{
d.manage().timeouts().implicitlyWait(60000, TimeUnit.MILLISECONDS);
d.get(d.getCurrentUrl());
WebDriverWait wait = new WebDriverWait(d, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(d.findElement(By.cssSelector("em.icon16.icon16-delete"))));
WebElement deleteLink=d.findElement(By.cssSelector("em.icon16.icon16-delete"));
deleteLink.click();
//JavascriptExecutor executor = (JavascriptExecutor) d;
//executor.executeScript("arguments[0].click();", deleteLink);
d.switchTo().alert().accept();
d.manage().timeouts().implicitlyWait(60000, TimeUnit.MILLISECONDS);
d.get(d.getCurrentUrl());
System.out.println("going out");
try{
Thread.sleep(5000);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
我的HTML代碼: -
圖標代碼: -
<div class="device-action-menu">
<div class="device-action-menu-placeholder"></div>
<span class="device-action-menu-arrow"></span>
<ul class="device-action-menu-ul">
取消發佈按鈕代碼: -
<li><a href="javascript:;" class="action-publish action_profile_unpublish" profilename="Test_Agent_1_Cleinrt" profileid="1764" rel="https://mysite/profilec/profileunpublish/1764" title="Unpublish Profile"><em class="icon16 icon16-wipe"></em></a></li>
刪除按鈕代碼: -
<li><a href="javascript:;" class="action-delete delete_action" rel="https://mysite/profilec/delete/1434" title="Delete Profile"><em class="icon16 icon16-delete"></em></a></li>
什麼是錯誤你找回?它是否無法點擊或者是啓動的動作,什麼都沒有發生?我發佈了一個可能有幫助的答案,因爲我有類似的問題。 – ratsstack