2012-05-31 23 views
0

我正在爲希望我做硒/ junit測試的客戶端工作,但整個用戶界面不顯示任何代碼的html代碼或標題該頁面只是像「歡迎進入......」那樣的內容,您應該如何檢查主頁上或登錄頁面上的內容?硒測試iterface錯過id和標題和其他明智的信息

這是HTML的一個例子:

<div class="site-body m-welcome" data-module="welcome"> 
<div class="inner"> 
    <h1 class="starred dark"><span>Welcome to ...</span></h1> 

    <div class="choices"> 
    <div class="choice"> 
     <a href="http://www.alink/account/validate/driver" class="btn btn-primary">Become a xxxxx</a> 
    </div> 

    <span class="or"><span>Or</span></span> 

    <form action="http://www.alink/welcome" method="post" class="choice" data-response-type="json"> 
       <input type="text" name="plate_number" id="car_plate_validation_plate_number" value="" maxlength="8" class="plate required numberplate" placeholder="Enter number plate"> 

     <button type="submit" class="btn btn-primary">Become an yyyyy</button> 

     <div class="invalid-message inline-modal" data-behavior="modal"> 
     <h1>Sorry - you are not eligible to join the company</h1> 


     <p>See <a href="#">am I eligile?</a> for full eligibility critera.</p> 
     </div> 
    </form> 
    </div> 
+0

顯示的頁面的示例HTML。 – Arran

回答

1

您可以使用XPath找到幾乎所有元素,但往往在你的情況下,我不會使用它(這裏什麼事都沒有標識),你可能會需要經常使用它:

IWebElement element = driver.FindElement(By.XPath, "//*[text='Welcome in ...']"); 

,將讓你擁有的其中的文本任何類型的第一個元素「歡迎......」

爲了檢查,如果你在某頁面,我猜測你必須搜索一個對該頁面而言是獨一無二的元素,而不是其他頁面。

如果你想要更具體的例子,你需要向我們展示一些HTML。 HTML的

+0

我在一個答案中發佈了一個例子::) – Shilaghae

+0

@Shilaghae因此,例如,以獲得'我是否是eligile?'點擊,你會發現FindElement(By.Xpath,「// a [text ='I I eligile?']」); – RoneRackal

+0

爲了能夠從您發佈的HTML示例中獲取元素,您應該更多地閱讀XPath。 http://www.w3schools.com/xpath/default.asp始終是一個很好的開始。 – RoneRackal

0

實施例:

<div class="site-body m-welcome" data-module="welcome"> 
    <div class="inner"> 
     <h1 class="starred dark"><span>Welcome to ...</span></h1> 

     <div class="choices"> 
      <div class="choice"> 
       <a href="http://www.alink/account/validate/driver" class="btn btn-primary">Become a xxxxx</a> 
      </div> 

      <span class="or"><span>Or</span></span> 

      <form action="http://www.alink/welcome" method="post" class="choice" data-response-type="json"> 
           <input type="text" name="plate_number" id="car_plate_validation_plate_number" value="" maxlength="8" class="plate required numberplate" placeholder="Enter number plate"> 

       <button type="submit" class="btn btn-primary">Become an yyyyy</button> 

       <div class="invalid-message inline-modal" data-behavior="modal"> 
        <h1>Sorry - you are not eligible to join the company</h1> 


        <p>See <a href="#">am I eligile?</a> for full eligibility critera.</p> 
       </div> 
      </form> 
     </div> 
+0

你能告訴我們哪個是上面的html中的獨特標籤可以幫助你區分頁面是登錄還是主頁。然後,我可以幫助您查找該頁面是否是使用硒的登錄頁面。 –

+0

這是問題,我只是這種代碼,它不是我寫的,但我必須測試它,我不能改變這個HTML。 :( – Shilaghae

+0

我可以理解你可以改變HTML,但是至少諸如「welcome in ..」等文本在主頁和登錄頁面中必須不同。 –