2016-03-24 15 views
-2

単純なボットを作ろうとしましたが、このエラーが発生しました。Javaエラー:適用できませんでした。java.lang.String

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 


public class Main { 
    public static void main(String[] args) throws InterruptedException { 

     WebDriver driver = new ChromeDriver(); 
     driver.get("https://***.com/#/"); 
     driver.findElement(By.xpath("//*[@id=\"homepage-hero\"]/a/img")).click(); // clicks site steam sign in button 
     WebElement steamUsername = driver.findElement(By.xpath("//*[@id=\"steamAccountName\"]")); 
     WebElement steamPassword = driver.findElement(By.xpath("//*[@id=\"steamPassword\"]")); 

     steamUsername.sendKeys("***"); 
     steamPassword.sendKeys("***"); 
     Thread.sleep(45000); 
     WebElement updatedBalance = driver.findElement(By.xpath("//*[@id=\"header-balance\"]")); 
     WebElement balance = driver.findElement(By.xpath("//*[@id=\"header-balance\"]")); 

     if(updatedBalance.getText() > balance.getText()); { 
      System.out.println("hello"); 
     } 

    } 
} 

    error: could not be applied too java.lang.String 
+2

投稿を編集し、COMPLETEエラーメッセージをコピー/貼り付けする必要があります。また、エラーが発生したコード内の行を識別します。 [help]にアクセスして[ask] –

答えて

1

私はあなたにエラーを与えたこのラインことを推測しています:

if(updatedBalance.getText() > balance.getText()); { 
    System.out.println("hello"); 
} 

あなたは、文字列を比較する>演算子を使用することはできません。それらの文字列が数値を表す場合は、最初に変換する必要があります。たとえば、使用している整数または任意の数値データ型に変換する必要があります。文字列を整数に変換する例として、Integer.valueOf(updateBalance.getText())を使用します。

if文の後ろにセミコロンがあることもわかりますが、あなたはそれがそこにあることを意味しないと思います。

0

ここで何をしようとしていますか?すべての

if(updatedBalance.getText() > balance.getText()); { 
      System.out.println("hello"); 
     } 

まず、System.out.println("hello");if()後ためセミコロンif()条件との関連はありませんが、それは間違いです。次に、文字列を ">"と比較して、何を得たいですか?文字列の長さを比較するには、updatedBalance.getText().length()を使用し、文字列が等しい場合はupdatedBalance.getText().equals(balance.getText())を使用します。

関連する問題