2017-02-01 1 views
0
<a id="ctl00_cphBody_gvMessageList_ctl02_hlnkMessageSubject" href="Message.aspx?id=3428&member=">DDM IT QUIZ 2017 – Bhubaneswar Edition</a> 

<a id="ctl00_cphBody_gvMessageList_ctl03_hlnkMessageSubject" href="Message.aspx?id=3427&member=">[Paybooks] Tax/investment declaration proof FY 2016-17</a> 

<a id="ctl00_cphBody_gvMessageList_ctl04_hlnkMessageSubject" href="Message.aspx?id=3426&member=">Reimbursement clarification</a> 

アウト:複数のWeb要素のwebdriverで相対xpathを取得するにはどうすればよいですか?

DDM IT QUIZ 2017 – Bhubaneswar Edition 

[Paybooks] Tax/investment declaration proof FY 2016-17 

Reimbursement clarification 

私は上記のテキストを得ることができるようにどのように私は、これらの三つの要素の相対XPathを得ることができます。

+0

ウェブサイトのURLを入力してください。 – BIJAY

+0

https://www.snapdeal.com/ –

+0

どのカテゴリにもカーソルを置いて、 –

答えて

0
xpath = '//a/text()' 

これは、テキスト

0

のリストを返します。完全な答えは次のようになります。

  • が持つこのような場合には、同じタイプのすべてのaの要素を取得するためにidctl00

    // a [contains(@id、 'ctl00')]

  • あなたは、たとえば、複数の制限を追加することができます彼の値に一定の文字列を格納するhref制限を、追加

    // [(@id、「ctl00」)が含ま] [「、(@hrefを含むメッセージすべてa要素を取得する「)]

  • だけのテキストを取得するために

    //

を使用するのに十分である、あなたのフレームワークからテキストを取得するための方法を使用することができますまたはdd /text()をxpath式に追加します。

0

マウス操作とキーボード操作に加えて、次の例のようにspanクラス[relative xpath]を使用できます。 これをチェックしてお知らせください!

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.interactions.Actions; 

public class SnapD { 
public static void main(String args[]){ 
WebDriver d=new FirefoxDriver(); 
d.get("https://www.snapdeal.com/"); 
d.manage().window().maximize(); 
d.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
System.out.println("Hello Google..."); 
System.out.println("Hello Snapdeal..."); 
WebElement wb= d.findElement(By.xpath("//span[text()='Electronics']")); 
Actions act=new Actions(d); 
act.moveToElement(wb); 
act.perform(); 
System.out.println("Mouse hovered"); 
WebElement wb1=d.findElement(By.xpath("//span[text()='DTH Services']")); 
act.contextClick(wb1).perform(); 
act.sendKeys(Keys.ARROW_DOWN,Keys.ENTER).perform(); 
act.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform(); 

} 
} 
+0

ありがとうございます。 –

+0

私はあなたを助けることができましたか? – BIJAY

+0

はい、ありがとうございます。私は相対的な道の概念を辿りました。 –

関連する問題