简体   繁体   English

硒测试xpath

[英]Selenium Testing xpath

Hey i need this xpath for list 嘿,我需要这个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诱导WebDriverWaitelementToBeClickable

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM