Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中检索Selenium WebElement的最小值?_Java_Selenium - Fatal编程技术网

如何在Java中检索Selenium WebElement的最小值?

如何在Java中检索Selenium WebElement的最小值?,java,selenium,Java,Selenium,我编写了一个简单的代码来刷新browsergame网页,并使用selenium web浏览器自动执行该网页上的任务 我做了一个小循环: while (true) { driver.findElement(By.linkText("Premium Exchange")); if (driver.findElement(By.id("premium_exchange_stock_wood") //<-- if the value of the wood stoc

我编写了一个简单的代码来刷新browsergame网页,并使用selenium web浏览器自动执行该网页上的任务

我做了一个小循环:

while (true) {
        driver.findElement(By.linkText("Premium Exchange"));
        if (driver.findElement(By.id("premium_exchange_stock_wood") //<-- if the value of the wood stock is 64 or higher){
            driver.findElement(By.name("buy_wood")).clear();
            driver.findElement(By.name("buy_wood")).sendKeys("64"); //enter 64 in the 'buy box'
            Thread.sleep(1000);
            driver.findElement(By.xpath("//input[@value='Calculate best offer ']")).click(); //click calculate best offer
            Thread.sleep(1000);
            driver.findElement(By.xpath("//div[@id='premium_exchange']/div/div[2]/button")).click(); //click buy
            Thread.sleep(10000);


        }
while(true){
driver.findElement(通过.linkText(“溢价交易所”));
if(driver.findElement(By.id(“premium\u exchange\u stock\u wood”)//使用.getText()和parseInt函数

String strVal=driver.findElement(By.id("premium_exchange_stock_wood").getText();//gets the value as string
int intVal=Integer.parseInt(strVal);converts string to integer
if (intVal>=64){
  //Perform further actions
}
注意:如果.getText()不起作用,可以使用.getAttribute(“innerHTML”)或.getAttribute(“outerHTML”)