4

I am new to Selenium and trying to build a project with it. I need to learn how to click a JS link. There are many items listed by pages. Pagination is done by JS, unfortunately. here is an example...

<ul class="pagination museo-700">
    <li class="first hidden disabled">
        <a href="#">First</a>
    </li>
    <li class="prev disabled">
        <a class="arrow" href="#">
            <img src="/areas/site/Content/images/page/pagination-prev-arrow.png">
        </a>
    </li>
    <li class="page active">
        <a href="#" class="active">1</a>
    </li>
    <li class="page">
        <a href="#">2</a>
    </li>
    <li class="page">
        <a href="#">3</a>
    </li>
    <li class="page">
        <a href="#">4</a>
    </li>
    <li class="page">
        <a href="#">5</a>
    </li>
    <li class="next">
        <a class="arrow" href="#">
            <img src="/areas/site/Content/images/page/pagination-next-arrow.png">
        </a>
    </li>
    <li class="last hidden">
        <a href="#">Last</a>
    </li>
</ul>

I would like to click pages 1., 2., 3. ,4. and 5. pages above. Please give me a clue

2 Answers 2

2

You could first locate the pager with a CSS selector and then each link by link text:

driver.FindElement(By.CssSelector("ul.pagination"))
      .FindElement(By.LinkText("1")).Click();

You could also use an XPath:

driver.FindElement(By.XPath("//a[@href='#'][text()='1']")).Click();
Sign up to request clarification or add additional context in comments.

Comments

2

code not tested but I feel like they should work

.page > a:contains("1")
.page > a:contains("2")
.page > a:contains("3")
.page > a:contains("4")
.page > a:contains("5")

or

//li[contains(@class, 'page')]/a[text()='1']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.