Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
125 views
in Technique[技术] by (71.8m points)

java - How to locate and type something in the textbox

public class testFluent {   

WebDriver driver;   
    @Before
        public void setUp(){        
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.manage().deleteAllCookies();}

         @Test
        public void myFirstFluent(){
        WebElement element;
        driver.get("http://www.yahoo.com");         
        element = myDynamicElement(By.id("//*[@id='p_13838465-p']"));
        System.out.println("Element found");
        }

        public WebElement myDynamicElement(final By locator){

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                    .withTimeout(10, TimeUnit.SECONDS)
                    .pollingEvery(100, TimeUnit.MILLISECONDS)
                    .ignoring(NoSuchElementException.class);

            WebElement element = wait.until(new Function<WebElement, WebDriver>(){

                public WebElement apply(WebDriver drv){
                    return drv.findElement(By.id(locator));
                }
            });

                return element;
        }

    }

I am unable to locate and ends with Error.

java.lang.Error: Unresolved compilation problems: The method until(Function) in the type Wait is not applicable for the arguments (new Function(){}) Function cannot be resolved to a type

The method id(String) in the type By is not applicable for the arguments (By) at com.junit.qa.testFluent.myDynamicElement(testFluent.java:49)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I hope this helps u..

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;  


public class yahoo {  

     FirefoxDriver Driver=null;
     WebDriverWait wait = null;



     @BeforeTest  
     public void start(){  
      Driver = new FirefoxDriver();  
     }  

    @Test 
     public void Test() throws InterruptedException{   
      wait=new WebDriverWait(Driver,90); 
      System.out.println("Loading yahoo search page");  
      Driver.get("http://www.yahoo.com");  
      System.out.println("Yahoo search page loaded fine");  
      WebElement text=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='p_13838465-p']")));
      text.sendKeys("selenium");
      Thread.sleep(5000);

     }  

     @AfterTest  
     public void close(){  
     Driver.quit();   
     }  
    }  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...