-2

if else ループを持つセレン Webdriver スクリプトがあります。スクリプトを実行すると、コードは常に最初の if 条件で停止し、else の部分にはまったく移動しません。そして、if条件がfalseであるため、例外が発生します。Selenium Web ドライバーのループ部分を回避する方法はありますか? コーディングにはC#を使用しています。前もって感謝します。

以下は、スクリプトで使用したループ構造です。

    if (driver.FindElement(By.Id("ctl00_ContentMain_Label_Error")).Text.Contains("The username is already registered with Current Brand"))
{
    //take a screen shot
}

else if (driver.FindElement(By.Id("ctl00_Label_WelcomeMessage")).Text == "You are not currently signed in")
{
    //take a screen shot
}
else if (driver.FindElement(By.Id("ctl00_ContentLeftNav_UserNavBar_MenuItemLogOut")).Text == "Log Out")
{

//take a screenshot
}
4

1 に答える 1

0

実際に投稿されたコードで、取得したテキストdriver.FindElement(By.Id("ctl00_Label_WelcomeMessage")).Textとあなたのown text.

Stringコードから取得したテキストは、データ型を返します。したがって、文字列操作の概念を使用して文字列データ型を比較できます。equalsequalsIgnoreCaseなどを使用してcontains...

これを試して:

 else if (driver.FindElement(By.Id("ctl00_Label_WelcomeMessage")).Text.equals("You are not currently signed in"))
{
//take a screen shot
}

それ以外の

else if (driver.FindElement(By.Id("ctl00_Label_WelcomeMessage")).Text == "You are not currently signed in")
{
//take a screen shot
}
于 2013-02-21T11:25:12.630 に答える