2017-03-15 1 views
-2

1つのXpathが表示されている場合にはテキストを印刷し、他のxpathが表示されている場合はテキストを表示します。しかし、If文で指定されたXpathではチェックが行われているが、Else Ifにスキップしていないことが確認されています。私が間違っているところ。助けてください!Selenium-java:elseを入力できませんXpathが表示されていないブロックの場合

if(driver.findElement(By.xpath("//*[@id='investmentsthird']/section[1]/section[1]/div/h3")).isDisplayed()) { 
    System.out.println("submitted"); 
} else if(driver.findElement(By.xpath("//*[@id='investmentsthird']/div[1]/div/div/h4")).isDisplayed()) { 
    System.out.println("failed"); 
} 
+1

をブロックする場合/他の前に、ページ上に存在していることを確認してください。 'else {System.out.println(" both are wrong ");}' – Guy

+0

"else if"条件が評価されているということを意味しますが、 "if block"条件が "true"を返して "投稿されました?? –

+0

小さなプログラムをデバッグする方法については、[mcve]、特に下のリンクをお読みください。 – JeffC

答えて

0

要素はおそらく、第2の条件はまた、偽の

WebdriverWait wait = new WebDriverWait(driver, 20) 
wait.until(ExpectedConditions.presenceOfElementLocated(by.xpath"//[@id='investmentsthird']/section[1]/section[1]/div/h3"))) 
if(driver.findElement(By.xpath("//*[@id='investmentsthird']/section[1]/section[1]/div/h3")).isDisplayed()) { 
    System.out.println("submitted"); 
} else if(driver.findElement(By.xpath("//*[@id='investmentsthird']/div[1]/div/div/h4")).isDisplayed()) { 
    System.out.println("failed"); 
} 
関連する問題