如何验证单击链接是否会在非常大的网页上显示屏幕上的特定部分

问题描述 投票:-1回答:1

我正在测试一个非常大的网页,当我点击菜单项时,网页的相关部分应该出现在屏幕上。请考虑以下代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WikipediaTest {
private WebDriver driver;
public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub

    System.setProperty("webdriver.chrome.driver", "C:/soft/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();

    driver.get("https://en.wikipedia.org/wiki/Main_Page");
    driver.findElement(By.id("searchInput")).sendKeys("WebDriver");
    driver.findElement(By.xpath("//*[@type='submit']")).click();
    Thread.sleep(2000 );
    driver.findElement(By.partialLinkText("Selenium Remote Control")).click();;
    Thread.sleep(5000); 

    // as expected, the section "Selenium Remote Control" section is being displayed on the screen.   
    // I am looking for a way to validate that the section or the text "Selenium Remote Control" is actually visible on the current screen. 

    driver.quit();}

}

我被困在可以验证当前屏幕上显示“Selenium Remote Control”的部分。我的项目有很多像这样的测试,我请求支持。

我们正在使用Selenium和Java(以及移动设备上的Appium)来测试这个应用程序。谢谢

java selenium selenium-webdriver appium
1个回答
0
投票

您可以尝试类似下面的示例:

在这里,我试图在维基百科中搜索“WebDriver”

driver.get("https://www.wikipedia.org/");
driver.findElement(By.id("searchInput")).sendKeys("WebDriver");
driver.findElement(By.xpath("//*[@type='submit']")).click();

现在是验证部分。包含“WebDriver”信息的页面标题为“Selenium(Software)”

String title = driver.findElement(By.cssSelector("#firstHeading")).getText();
if (title.contentEquals("Selenium (software)"))
    System.out.println("Test Passed!");
else
    System.out.println("Test Failed!");

因此,您可以使用任何一个定位器定义元素的属性,然后进行比较。

© www.soinside.com 2019 - 2024. All rights reserved.