2017-05-20 9 views
1

Seleniumでリンク(リンクテキストは「Pearson eText」)を識別しようとしています。 By.linkText、By.xpath、さらにはBy.tagNameを使ってみましたが、これらのどれもうまくいかないようです。要素を特定する方法が他にもある場合は、誰かが私に知らせることができるかどうか疑問に思っていました。以下は、Webページのhtmlコードです。前もって感謝します!xpathでも識別できない場合、SeleniumでWeb要素を識別する方法


<div class="container_12" style="margin-bottom:10px;"> 
      <div class="grid_5" id="studlinks"><h3><a href="javascript:launch('71053')">Welcome to MasteringAandP</a></h3><p>Access all your Mastering course resources and assignments 
</p><h3><a href="javascript:launch('164')">Mastering Assignments</a></h3><p>Access Mastering homework assignments.</p><h3><a href="javascript:launch('165')">Mastering Scores (for students)</a></h3><p>Access your results for all Mastering work you have completed. </p><h3><a href="javascript:launch('170')">User Settings</a></h3><p>Manage your Pearson account information.</p><h3><a href="javascript:launch('171')">Pearson eText</a></h3><p>Access your Pearson eText.</p><h3><a href="javascript:launch('172')">Study Area</a></h3><p>Access the self Study Area to watch videos and animations, take practice quizzes and more. Your work in the Study Area does not report to your instructor's grade book. To complete instructor-assigned activities, go to Assignments.</p><h3><a href="javascript:launch('105')">MasteringAandP Course Home</a></h3><p>Access your MasteringAandP course for additional content and assignments.</p></div> 
      <div class="grid_5" id="instlinks"></div> 
     </div> 

+0

あなたがリンクテキストによる検索を使用しなかったんでした''あなたのPearson eTextにアクセスするか '' Pearson eText''だけにアクセスできますか? – Dillanm

答えて

0

いくつかの方法があります。あなたは、XPathのために行く場合、それはあなたを絶望ではないだろう、

WebElement personETextLink = driver.findElement(By.cssSelector("a[href=\"javascript:launch('171')\"]")); 

そして:CSSセレクタの方法の一つがある可能性があります。 XPathのでLINK要素を見つける

WebElement personETextLink = driver.findElement(By.xpath("//*[@href=\"javascript:launch('171')\"]")); 
0

//a[text()='Pearson eText'] 

あなたはHREFを取得したい場合は、簡単に行うことができます

//a[text()='Pearson eText']/@href 
関連する問題