我想提出一個if條件,當存在id="prog_bg"
或class="progress_box_bg"
時,執行剩餘的代碼。 DOM如下,如果條件,在id =「prog_bg」存在的情況下,執行剩餘的代碼
<div id="wizard">
<div class="quote_header">
<div class="items">
<div id="top-line" style="display: block;">
<div class="back_box">
<div class="progress_box">
<div id="prog_bg" class="progress_box_bg" style="width: 75px;"></div>
</div>
</div>
<div id="service-div" class="page" style="padding-top:45px; >">
<div id="propertytype-div" class="page">
我試了很多選擇,但它不會工作。夥計讓我知道它是怎麼做到的?
if (var.equals(driver.findElement(By.tagName("body")).getText().contains("prog_bg")))
try { if (selenium.getHtmlSource().matches("^[\\s\\S]*prog_bg[\\s\\S]*$")) break; } catch (Exception e) {};
if(driver.getPageSource().matches("^[\\s\\S]*prog_bg[\\s\\S]*$"))
if(driver.findElement(By.id("prog_bg")).isDisplayed())
if (driver.findElement(By.className("progress_box_bg")).isDisplayed())
感謝, 薩欽
的可能的複製[檢查元件最好的方式是不與Java本webdriver的硒(http://stackoverflow.com/questions/12270092/best-way-to-check-that-element-is-not-本-的webdriver - 硒與 - 爪哇) –