Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

I am trying to identify a link (link text is 'Pearson eText') in Selenium. I have tried using By.linkText, By.xpath and even By.tagName but none of these seems to work. I was wondering if someone can let me know if there are more ways to identify an element. Following is the html code from the webpage. Thanks in advance!

<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>

1 Answer

0 votes
by (62.9k points)

Finding the Link element by xpath:

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

If you want to get the href, you can easily do:

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

Browse Categories

...