Java程序中的Xpath selenium WebDriver错误



我有一个有效的xpath,但是当我在java中使用相同的Xpath来存储WebElements时,它给出了一个错误。它与语法错误有关。下面是错误令牌 "]//div/div/button[@id="上的语法错误, ( 预计 - 令牌"标头"上的语法错误,删除此令牌 - 令牌"]"、( 上的语法错误,预期

below is the httml code

 <div id="header-wrap-container">
<div id="header-wrap" style="position: fixed;">
<div class="bredcrumDJV">
<div class="container">
<div class="row">
<div class="col-md-5 col-lg-6">
<div class="col-md-7 col-lg-6 col-xs-12 applySec">
<div class="pull-right hidden-xs">
<button id="applybtn-2" class="btn btn-primary btn-lg dice-btn apply disableButton" type="button" data-toggle="modal" data-target="#cover-resume-modal">Apply Now</button>
<div class="hidden-xs btn-group btn-group-lg">
<div class="visible-xs btn-group btn-group-lg btn-block">
<input id="partnerSurveyURL" value="https://partner.techpapers.com/interstitial/interstitial.aspx?promo=111186" type="hidden"/>
</div>
<div class="visible-xs">
<button id="applybtn-2" class="btn btn-primary btn-lg dice-btn apply disableButton" type="button" data-toggle="modal" data-target="#cover-resume-modal">Apply Now</button>
<div class="hidden-xs btn-group btn-group-lg">
<div class="visible-xs btn-group btn-group-lg btn-block">
<input id="partnerSurveyURL" value="https://partner.techpapers.com/interstitial/interstitial.aspx?promo=111186" type="hidden"/>
</div>
<ul class="list-inline details pull-right djvReport hidden-xs" style="margin-top: 10px; clear: both;">
</div>
</div>
</div>
</div>
</div>
<!-- START REPORT MODAL -->
xpath 是 .//*[@id=">

header-wrap-container"]//div/div/button[@id="applybtn-2"]

在 Java 程序中插入了相同的 xpath。

public class FileUpload {
    @Test()
    public void checkAlertWindow() throws InterruptedException
    {
        System.setProperty("webdriver.gecko.driver", "C:\geckodriver\geckodriver.exe");
        WebDriver webdriver = new FirefoxDriver();
    webdriver.get("https://www.dice.com/jobs/detail/Mobile-Test-Automation-Engineer-Etouch-Systems-Corp-Fremont-CA-94555/etouch/734212?icid=sr2-1p&q=NightWatch,Selenium&l=Fremont");
//By bye = By.xpath(".//*[@id="header-wrap-container"]");
    //  + "/button[@id="applybtn-2"]");
    //By b = By.xpath(".//*[@id="header-wrap-container"]");
//  webdriver.findElement(By.xpath(".//*[@id="header-wrap-container"]"));
    WebElement myDynamicElement = (new WebDriverWait(webdriver, 10))
              .until(ExpectedConditions.presenceOfElementLocated(By.id("header-wrap-container")));
    System.out.println(myDynamicElement.getText());
    By byeid = By.id("header-wrap-container");
webdriver.findElement(By.xpath(" .//*[@id="header-wrap-container"]//div/div/button[@id="applybtn-2"]"));

}
}

为什么程序给出错误?

您需要

转义语句中的 " 或使用 '

试试这个:

webdriver.findElement(By.xpath(" .//*[@id="header-wrap-container"]//div/div/button[@id="applybtn-2"]"));

最新更新