2016-05-10 29 views
1

C#、Selenium webdriverを使用すると、キャッシュされた資格情報の有無に応じて、ログイン画面にリダイレクトされるか、最終的に実際のアプリケーションページにリダイレクトされるページに移動します。 (大文字の空白アクティブディレクトリ認証の場合)。ExpectedConditions OR AND and DefaultWait <T>

私の後には、自分のアプリページの既知の要素が表示されるか、要素ID「use_another_account_link」のazure authのログイン画面が表示されます。だから、それぞれのN秒を待つことなく、ExpectedConditionsの条件をORしたいと思う。

答えて

1

あなたはORを実装するために,で区切られた2つのexpessionsとCSSセレクタを使用することができます。

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); 
var element = wait.Until(ExpectedConditions.ElementExists(By.CssSelector("#id1, #id2"))); 
if (element.GetAttribute("id") == "id1") { 
    // handle element with id="id1" 
} else { 
    // handle element with id="id2" 
} 

または2つのエクスペリエンスを持つXPathを|

var element = wait.Until(ExpectedConditions.ElementExists(By.XPath("id('id1') | id('id2')"))); 
if (element.GetAttribute("id") == "id1") { 
    // handle element with id="id1" 
} else { 
    // handle element with id="id2" 
} 
+0

答えに感謝します – dgorti

0

Func<IWebElement, IWebElement>IWait<IWebElement>.Until()に自分自身を入力する必要がある場合です。あなたは、このような具体的な何かを書くことができます。

(Func<IWebElement, IWebElement>) 
    (return ExpectedConditions.ElementExists(By.Id("use_another_account_link")) 
    || ExpectedConditions.ElementExists(By.Id("your_login_field_id"))) 

またはこのような一般的な何か:

public Func<IWebElement, IWebElement> Or(Func<IWebElement, IWebElement> either, 
             Func<IWebElement, IWebElement> or) { 
    return (Func<IWebElement, IWebElement>) either || or; 
} 
+0

ここでは、どちらのコードスニペットもコンパイルまたはテストしていないことに注意してください。しかしそれはそれのようなものです。 –

+0

さらに良いオプションは、しばしば、ページのトップIDをチェックすることです(トップdivに1つのIDがあるかもしれません)。 99.9%は十分です:) –

+0

ElementExistsはそうではありません。要素が現れるのを待っているようではありません。問題は、Webページ上で複数のリダイレクトが発生し、最終的に最終ページに到着する可能性があり、要素が中間ページに存在しない場合、ElementExistsはすぐに返されるように見えるということです。 – dgorti

関連する問題