我正在编写脚本,导航到菜单并单击菜单按钮,它将导航到特定页面,再次验证页面标题是否符合预期,然后单击第二个菜单按钮并对所有菜单按钮重复相同的过程。
这是html代码
<md-menu-content width="6" role="menu">
<md-menu-item>
<button class="md-button md-ink-ripple" ng-transclude="" type="button" ng-click="gotoPost()" role="menuitem" aria-label="Create A Post">
<span class="ng-scope">Creae A Post</span>
<div class="md-ripple-container" style=""/>
</button>
</md-menu-item>
<md-menu-divider role="separator"/>
<md-menu-item>
<button class="md-button md-ink-ripple" ng-transclude="" type="button" ng-click="goToProfile()" role="menuitem" aria-label="PROFILE">
<span class="ng-scope">PROFILE</span>
<div class="md-ripple-container" style=""/>
</button>
</md-menu-item>
<md-menu-divider role="separator"/>
// And so on ..............
这是我的硒代码:
验证个人资料链接
WebElement mnuElement = driver.findElement(By.xpath("//html/body/access/allow-intent/allow-intent/allow-intent/allow-intent/allow-intent/allow-intent/allow-navigation/allow-navigation/main-navigation/div/md-menu/img"));
// Move cursor to the Main Menu Element
Actions builder = new Actions(driver);
builder.moveToElement(mnuElement, 764, 90).click(mnuElement);
builder.perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
WebElement submnuElement = driver.findElement(By.xpath(".//*[@id='menu_container_3']/md-menu-content/md-menu-item[1]/button"));
// Clicking on the Hidden SubMenu
//driver.findElement(By.Id("sbEle")).Click();
submnuElement.click();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
//0OSP.SelectOption().click();
//0driver.manage().timeouts().implicitlyWait(550, TimeUnit.SECONDS);
//0OSP.Clicklogadive().click();
//0driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
Recreational RC = new Recreational(driver);
System.out.println(driver.getCurrentUrl());
driver.navigate().refresh();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
String post= RC.Getrtitle().getText();
System.out.println(post)
Assert.assertEquals(post, "Create Post");
System.out.println("\n! You have landed to the page: " +post + "Page");
driver.navigate().back();
// ************* VERIFY PROFILE LINK ***********************
driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
WebElement mnuElement1 = driver.findElement(By.xpath("//html/body/access/allow-intent/allow-intent/allow-intent/allow-intent/allow-intent/allow-intent/allow-navigation/allow-navigation/main-navigation/div/md-menu/img"));
// Move cursor to the Main Menu Element
Actions builder1 = new Actions(driver);
builder1.moveToElement(mnuElement1, 764, 90).click(mnuElement1);
builder1.perform();
Thread.sleep(5000L); // Giving 10Secs for submenu to be displayed
WebElement submnuElement1 = driver.findElement(By.xpath(".//*[@id='menu_container_3']/md-menu-content/md-menu-item[2]/button"));
// Clicking on the Hidden SubMenu
submnuElement1.click();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
Profile PF = new Profile(driver);
System.out.println(driver.getCurrentUrl());
driver.navigate().refresh();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
String profiletitle = PF.Getptitle().getText();
Assert.assertEquals(profiletitle, "Profile");
System.out.println("\n! You have landed to the page: " +profiletitle + "Page");
- 我的脚本点击创建帖子菜单按钮,转到该页面,验证页面标题并返回主页。这里我想选择第二个菜单按钮,但此时脚本停止。
请帮忙。