Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:19:40+00:00 2026-06-01T09:19:40+00:00

While writing selenium testcases for a webapplication I’m having trouble with the xpath selector.

  • 0

While writing selenium testcases for a webapplication I’m having trouble with the xpath selector. The element of the HTML-code which should be clicked on by Selenium is the following:

<a title="Voeg een vak toe" href="#" onclick="javascript:$.colorbox({width:818,href:'/olo-cleanjump/profiel/addVakForm'}); return false;">
  <p class="add">
    <img class="add-icon" src="/olo-cleanjump/static/images/icon_add.png"/>
    Voeg vak toe
  </p>
</a>

The Selenium IDE plugin for firefox gives me the following selenium code for this:

driver.findElement(By.cssSelector("p.add")).click();

The addVakForm javascript function that is called by this link opens a colorbox with the following HTML (I shortened it, there are around 30 similar div’s with class “lesboek_popup”) inside:

<div id="cboxLoadedContent" style="display: block; width: 776px; overflow: auto; height: 653px;">
  <div id="profielpagina_add">
    <h2>Voeg een vak toe aan je profiel</h2>
    <div class="lesboek_popup">
      <a class="content" href="/olo-cleanjump/profiel/addvak/120776">
        <img src="" alt="">
      </a>
      <p class="caption">
        <a href="/olo-cleanjump/profiel/addvak/120776">Engels</a>
      </p>
    </div>
    <div class="lesboek_popup">
      <a class="content" href="/olo-cleanjump/profiel/addvak/120786">
        <img src="" alt="">
      </a>
      <p class="caption">
        <a href="/olo-cleanjump/profiel/addvak/120786">Biologie</a>
      </p>
    </div>
  </div>

For the test I want to open the ‘Biologie’ link. Selenium IDE got me the following selenium code to do this

driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click();

to select this biology link element.
Based on this I wrote the following testcase:

 Test
public void testAddRemoveVak() throws Exception {
    this.get("");

    // vak 1 toevoegen
    driver.findElement(By.cssSelector("p.add")).click();
    driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click();

    // vak 2 toevoegen
    driver.findElement(By.cssSelector("p.add")).click();
    driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click();

    assertEquals(driver.findElements(By.xpath("//li[@class='vak']")).size(), 2);

    // vak 2 verwijderen
    this.get("profiel/removevak/120791");

    assertEquals(driver.findElements(By.xpath("//li[@class='vak']")).size(), 1);
}

The part

driver.findElement(By.cssSelector("p.add")).click(); 

actually was successful, so after this call the colorbox should be loaded. However the

driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click();

causes an NoSuchElementException, while this element definitely is present in the colorbox when I check for myself (the call/xpath was even autogenerated by Selenium IDE). Does anyone have a clue what may cause the NoSuchElementException?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:19:42+00:00Added an answer on June 1, 2026 at 9:19 am

    Probably you should wait when your popup appears. Try to use Implicit waits

    WebDriver driver = new FirefoxDriver();
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
    

    Also instead of xpath you can use driver.FindElement(By.LinkText("Biologie")).click() if it the only link with text Biologie on your page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
Today while writing some Visual C++ code I have come across something which has
While writing some C code, I decided to compile it to assembly and read
While writing code, it is pretty common to request a page with an appended
Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
While writing JavaScript code, I Separate each code block with <script> tags <script type=text/javascript>
While writing a small paint-like application (for myself), I originally had the following code
While writing var e = element.NextSibling as HtmlElement; I get an invalid cast exception.
While writing some code i came across this issue: #include <iostream> class random {
While writing code, I often run into the problem of addressing trivial dependancies. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.