简体   繁体   English

如何在硒webdriver中从一个java类(页面)到另一个TestNG类(test)调用下拉值?

[英]How to call dropdown value from one java class(page) to another TestNG class(test) in selenium webdriver?

I want to select and store a dropdown value in one element in a page(java class) and call it from different class. 我想选择一个下拉值并将其存储在页面(java类)的一个元素中,并从其他类调用它。

EX : i am doing like this for all other fields EX:我在所有其他领域都这样做

public class Home_page {

    private static WebElement element = null;

    public static WebElement txtbox_FirstName(WebDriver driver) {
        element = driver.findElement(By.id("u_0_g"));
        return element;
    }
}

public class Action_createAccount {

    private static WebDriver driver = null;

    public static void main(String args[]) {

    System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
    driver.get("https://www.facebook.com/");


    Home_page.txtbox_FirstName(driver).sendKeys("Anu");
   }
}

and this is working perfectly. 这很正常。 I am not able to write code for drop down to work in the same way. 我无法编写代码以同样的方式工作。 Please help 请帮忙

If you want to select birth day, the sample code is here. 如果要选择出生日期,示例代码在此处。 it may help you. 它可能会帮助您。

public class Home_page {
    private static WebElement element = null;

    public static WebElement txtbox_FirstName(WebDriver driver) {
        element = driver.findElement(By.id("u_0_g"));
        return element;
    }
    Public static WebElement dropdown_BirthDay_Day(WebDriver driver){
        element = driver.findElement(By.id("day"));
        return element;
    }
    Public static WebElement dropdown_BirthDay_Month(WebDriver driver){
        element = driver.findElement(By.id("month"));
        return element;
    }Public static WebElement dropdown_BirthDay_Year(WebDriver driver){
        element = driver.findElement(By.id("year"));
        return element;
    }

}

public class Action_createAccount {

    private static WebDriver driver = null;

    public static void main(String args[]) {

        System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        driver.get("https://www.facebook.com/");


        Home_page.txtbox_FirstName(driver).sendKeys("Anu");
        new Select(Home_page.dropdown_BirthDay_Day(driver)).selectByVisibleText("16");
        new Select(Home_page.dropdown_BirthDay_Month(driver)).selectByVisibleText("Nov");
        new Select(Home_page.dropdown_BirthDay_Year(driver)).selectByVisibleText("1990");
    }
}

暂无
暂无

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

相关问题 如何将全局变量从一个测试类传递到另一个测试类并在 selenium 的下拉列表中选择该值? - How to pass the global variable from one Test class to another test class and select that value in a dropdown in selenium? 如何使用带有Java的Selenium WebDriver将一个类的值传递给另一个类? - How can I pass one class value into another class using Selenium WebDriver with Java? 如何使用selenium和java中的testng从另一个class获取字符串值 - How to get string value from another class using selenium and testng in java 调用Java类(Selenium WebDriver,TestNG)时出错 - Error calling a java class (Selenium WebDriver, TestNG) 如何在Selenium Webdriver中将值从一个测试用例传递到另一个 - how to pass a value from one test case to another in selenium webdriver 如何在Selenium WebDriver中调用Java类? - How to call a java class in selenium webdriver? 如何将我的Eclipse Maven Selenium Webdriver TestNG Java项目从一台PC转移到另一台PC? - How to transfer my Eclipse Maven Selenium Webdriver TestNG Java project from one PC to another? 如何在 testNG 中实现从一个测试类到另一个测试类的控制流? - How do I make the control flow from one test class to another test class in testNG? 如何在Java中将字符串值从一个类调用到另一个类 - How to call String value from one class to another in Java 如何在Java(Android)中将变量的值从一个类调用到另一个类 - How to call the value of variables from one class to another in Java (Android)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM