简体   繁体   中英

How to use static objects in a class and how can we inherit the static object in other class

I am working in a selenium webdriver project.Here is my Framework shown in screenshot given below: 在此处输入图片说明

Here is the sample code , where I need to extend a static variable and a static object to another class.But when I try to extend the class , it shows some limitations in access modifiers.

package com.AFE_Framework;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
public class A 
{
   public static int dropdown_element_count;

   static WebElement afeTemplates;

   public static void Method_A (String A, String B)
   {
    WebElement createafeDiv = driver.findElement(By.xpath(xpathvalue1));
        List<WebElement> afeTemplates = createafeDiv.findElements(By
                .xpath(xpathvalue2));

   }


}
==========================================================================
package com.AFE.TestCase

import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import com.AFE_Framework.*;


public class B extends Class A 
{
  public static void Manage()   
    {
    **dropdown_element_count = afeTemplates.size() < --Here I am getting the error** 
    }

}

So can any one please help me to sort out this issue ?*

This error is not related to static. Error is related to type mismatch.

Also I believe you are trying to count size in dropdown. I would suggest you to use Select class.

package com.AFE.TestCase

import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import com.AFE_Framework.*;


public class B extends Class A 
{
  public static void Manage()   
    {
        Select se = new Select(driver.findElement(afeTemplates);


    List<WebElement> l = se.getOptions();

    dropdown_element_count = l.size();
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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