如何使用 selenium Junit 验证页脚文本
How can I verifying a footer text using selenium Junit
我想验证页脚中的文本。我通常复制 XPath 定位器并查找元素,然后获取元素的文本,但在 Junit 中此代码部分没有任何反应。
我需要从这个网站获取页脚文本:
这是我为此使用的代码。我知道还有另一种方法。
public class QAA_mock3 {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = utils.HelperFunctions.createAppropriateDriver("Chrome");
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@Test
public void test() {
String ExpTitle = "QAAgility" ;
Actions actions = new Actions(driver);
By TwitterLink = By.xpath("//*[@id=\"custom_html-4\"]/div/div[1]/a[2]");
By footer = By.xpath("//div[@id='footer']");
By imglogo = By.cssSelector("img.header-image");
driver.get(" https://www.qaagility.com");
System.out.println("Loaded page...");
String ActTitle = driver.getTitle();
System.out.println("page Title..."+ ActTitle);
if(ActTitle.contains(ExpTitle)) {
System.out.println("Verified the title for ..."+ ExpTitle);
}
else
System.out.println("Title verification went wrong...");
WebElement imgSize = driver.findElement(imglogo);
Dimension imageSize = imgSize.getSize();
int Height = imageSize.getHeight();
int Width = imageSize.getWidth();
System.out.println("The size of the Logo is : Width = "+ Width + "; Height = "+Height);
WebElement Twitter = driver.findElement(TwitterLink);
String Href = Twitter.getAttribute("href");
System.out.println("Twitter Link is :"+ Href);
WebElement footerText = driver.findElement(footer);
System.out.println("WebElement for footer is"+ footerText);
actions.moveToElement(footerText).build().perform();
String FTText = footerText.getText();
System.out.println("Footer Text is :"+ FTText);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
你错误地定义了页脚定位器:
By footer = By.xpath("//div[@id='footer']");
试试这个:
By footer = By.className("copyright-bar")
我想验证页脚中的文本。我通常复制 XPath 定位器并查找元素,然后获取元素的文本,但在 Junit 中此代码部分没有任何反应。
我需要从这个网站获取页脚文本:
这是我为此使用的代码。我知道还有另一种方法。
public class QAA_mock3 {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = utils.HelperFunctions.createAppropriateDriver("Chrome");
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@Test
public void test() {
String ExpTitle = "QAAgility" ;
Actions actions = new Actions(driver);
By TwitterLink = By.xpath("//*[@id=\"custom_html-4\"]/div/div[1]/a[2]");
By footer = By.xpath("//div[@id='footer']");
By imglogo = By.cssSelector("img.header-image");
driver.get(" https://www.qaagility.com");
System.out.println("Loaded page...");
String ActTitle = driver.getTitle();
System.out.println("page Title..."+ ActTitle);
if(ActTitle.contains(ExpTitle)) {
System.out.println("Verified the title for ..."+ ExpTitle);
}
else
System.out.println("Title verification went wrong...");
WebElement imgSize = driver.findElement(imglogo);
Dimension imageSize = imgSize.getSize();
int Height = imageSize.getHeight();
int Width = imageSize.getWidth();
System.out.println("The size of the Logo is : Width = "+ Width + "; Height = "+Height);
WebElement Twitter = driver.findElement(TwitterLink);
String Href = Twitter.getAttribute("href");
System.out.println("Twitter Link is :"+ Href);
WebElement footerText = driver.findElement(footer);
System.out.println("WebElement for footer is"+ footerText);
actions.moveToElement(footerText).build().perform();
String FTText = footerText.getText();
System.out.println("Footer Text is :"+ FTText);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
你错误地定义了页脚定位器:
By footer = By.xpath("//div[@id='footer']");
试试这个:
By footer = By.className("copyright-bar")