简体   繁体   English

如何从网站获取数据并在 excel Page object model 中打印

[英]How to fetch data from website and print in excel Page object model, Data driven and page factory this is hybrid framework

**Element Page**
public class BasePage {
  @FindBy(className = "_42ft _4jy0 _52e0 _4jy6 _4jy1 selected _51sy")//Signin Button
    private WebElement SigninButton;
    public void clickOnSigninButton() {
        SigninButton.click();
    }

    @FindBy(className= "pam _3-95 _9ay3 uiBoxRed")//Get Username erroe msg
    private WebElement geterrormsg;
    public String ClickonAdmissionnumber() {
        geterrormsg.getText();
    }
}
**Another Class Test case page**
public class Tc_1 {
public void  LoginTC1() throws Exception
{       
**//create page objects**
  BasePage lp = new BasePage();     
**//invoke the methods**
  lp.clickOnSigninButton();
  lp.Errormsg();
**//write actual data to excel**
ExcelLibrary.writeData("Sheet1", 1, 5, Actualmsg);
}    

Trying to fetch text from this class attribute?试图从此 class 属性中获取文本? I have tried with get attribute value but not able to fetch data.我尝试过获取属性值但无法获取数据。 Please help me out.... text output "Wrong credentials Invalid username & Password".请帮帮我.... 文本 output“凭据错误,用户名和密码无效”。

在此处输入图像描述

Code:代码:

package selenium;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class SaikumarFbTest extends WebDriverSetup {

    public static void main(String[] args) {
        
        // wrapped driver initialization
        WebDriver driver = startChromeDriver();
        
        //entering url
        driver.get("https://www.facebook.com/login");
        
        // accept cookie consent in CZ
        driver.findElement(By.xpath("//button[contains(@data-testid,'cookie-policy-dialog-accept-button')]")).click();  
        
        // switch to english using link in footer
        driver.findElement(By.xpath("//a[contains(@href,'https://www.facebook.com/login')]")).click();
        
        //accept cookie consent in EN
        driver.findElement(By.xpath("//button[contains(@data-testid,'cookie-policy-dialog-accept-button')]")).click();  

        // click login button
        driver.findElement(By.id("loginbutton")).click();
        
        // get <div class="clearfix _5466 _44mg" id="email_container"></div>
        WebElement emailContainer = driver.findElement(By.id("email_container"));
        
        // get child divs
        List<WebElement> emailContainerChildDivs = emailContainer.findElements(By.tagName("div"));
        
        // print error text
        System.out.println(emailContainerChildDivs.get(1).getText());
        driver.quit();
    }
    
}

Output: Output:

Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 23066
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Pro 10, 2021 11:30:39 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
The email or mobile number you entered isn’t connected to an account. Find your account and log in.

To save the text to XLSX file, use Apache POI -> https://www.codejava.net/coding/how-to-write-excel-files-in-java-using-apache-poi .要将文本保存到 XLSX 文件,请使用 Apache POI -> https://www.codejava.net/coding/how-to-write-excel-files-in-java-using-apache-poi

**Element Page**
public class BasePage {
  @FindBy(className = "_42ft _4jy0 _52e0 _4jy6 _4jy1 selected _51sy")//Signin Button
    private WebElement SigninButton;
    public void clickOnSigninButton() {
        SigninButton.click();
    }

    @FindBy(className= "pam _3-95 _9ay3 uiBoxRed")//Get Username erroe msg
    private WebElement geterrormsg;
    public String ClickonAdmissionnumber() {
       return geterrormsg.getText();
    }
}
**Another Class Test case page**
public class Tc_1 {
public void  LoginTC1() throws Exception
{       
**//create page objects**
  BasePage lp = new BasePage();     
**//invoke the methods**
  lp.clickOnSigninButton();
  String Actualmsg = lp.Errormsg();
**//write actual data to excel**
ExcelLibrary.writeData("Sheet1", 1, 5, Actualmsg);
}    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在页面对象模型中读取Excel数据 - Read excel data in page object model 我们如何将json对象从servlet传输到jsp页面,以及如何在jsp页面中获取json数据? - How can we transfer json object from servlet to a jsp page and how to fetch that json data in jsp page? 在页面对象模型框架中存储数据的最佳方法是什么 - What is the best way to store data in a Page Object Model Framework 页面对象模型中需要页面工厂 - Need of page factory in page object model Selenium Grid与页面对象模型页面工厂 - Selenium Grid With Page Object Model Page Factory 如何将页面对象工厂框架用于webelement的子元素 - how to use page object factory framework for child elments of a webelement 如何从Struts 2中动态生成的JSP页面获取数据? - How to fetch data from dynamically generated JSP page in Struts 2? 我正在将 TestNg 用于数据驱动框架,但未从 excel 中获取数据 - I am using TestNg for data driven framework,but data is not fetching from excel 当框架是Hybrid并且测试用例是由Selenium中的excel驱动时,如何使用TestNG注释? - How to use TestNG annotations when the framework is Hybrid and test cases are driven by excel in Selenium? Selenium 页面对象模型框架 - Selenium Page Object Model Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM