[英]Selenium Testing xpath
get li
tag with attribute id
li_myaccount and then get its parent ul
tag using ancestor::tagName
获取具有属性
id
li_myaccount的 li
标签,然后使用ancestor::tagName
获取其父ul
标签。
//li[@id='li_myaccount']//ancestor::ul
This should be what you are looking for :) 这应该是您要寻找的:)
By populateDropDown= By.xpath("(//a[@data-toggle='dropdown']/i)[2]");
By loginOption = By.xpath("(//ul[@class='dropdown-menu']/li[1]/a[1])[2]");
By signUpOption = By.xpath("(//ul[@class='dropdown-menu']/li[2]/a[1])[2]");
WebDriverWait wait = new WebDriverWait(driver, 10);
// Populate drop down
WebElement dropDown = driver.findElement(populateDropDown);
wait.until(ExpectedConditions.elementToBeClickable(dropDown));
dropDown.click();
// Click login
WebElement login = driver.findElement(loginOption)
wait.until(ExpectedConditions.elementToBeClickable(login));
login.click();
// OR click signUpOption
WebElement signUp = driver.findElement(signUpOption);
wait.until(ExpectedConditions.elementToBeClickable(signUp));
signUp.click();
You need to first click on My Account
link and then need to click Login
or Sign Up
link. 您需要先单击“
My Account
链接,然后再单击“ Login
或“ Sign Up
链接。
Induce WebDriverWait and elementToBeClickable
with following xpath. 使用以下xpath诱导WebDriverWait和
elementToBeClickable
。
To click on Login
link 点击
Login
链接
Click on My Account
点击我的帐户
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement eleMyaccount = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='collapse navbar-collapse']//ul//li[@id='li_myaccount']//a[contains(.,'My Account')]//i")));
eleMyaccount.click()
Click on Login link
点击登录链接
WebElement eleLogin = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='collapse navbar-collapse']//ul[@class='dropdown-menu']//li//a[contains(.,'Login')]")));
eleLogin.click()
To click on Sign Up
link 单击
Sign Up
链接
Click on My Account
点击我的帐户
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement eleMyaccount = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='collapse navbar-collapse']//ul//li[@id='li_myaccount']//a[contains(.,'My Account')]//i")));
eleMyaccount.click()
Click on Sign Up link
点击注册链接
WebElement eleSignUp = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='collapse navbar-collapse']//ul[@class='dropdown-menu']//li//a[contains(.,'Sign Up')]")));
eleSignUp.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.