如何在Java中检索Selenium WebElement的最小值?
我编写了一个简单的代码来刷新browsergame网页,并使用selenium web浏览器自动执行该网页上的任务 我做了一个小循环:如何在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
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”)