2017-04-11 70 views
0

我有一個有效的xpath,但是當我在java中使用相同的Xpath來存儲WebElements時,它會給出一個錯誤。 它與語法error.Below是錯誤 語法錯誤上令牌「」]/div/div /按鈕[@ id =「」, (預計 - 令牌「標題」上的語法錯誤,刪除此令牌 - 令牌 「」] 「」)語法錯誤預期java程序中的Xpath selenium WebDriver錯誤

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"]")); 


} 
} 

爲什麼程序給出錯誤?

回答

0

你需要或者逃避「你的發言或使用'

裏面試試這個:。

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

哦I C道理我想和它的作品的感謝! – vijaya