Note that there are some explanatory texts on larger screens.

plurals
  1. PONoSuchElementException with unknown cause using Selenium
    primarykey
    data
    text
    <p>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:</p> <pre><code>&lt;a title="Voeg een vak toe" href="#" onclick="javascript:$.colorbox({width:818,href:'/olo-cleanjump/profiel/addVakForm'}); return false;"&gt; &lt;p class="add"&gt; &lt;img class="add-icon" src="/olo-cleanjump/static/images/icon_add.png"/&gt; Voeg vak toe &lt;/p&gt; &lt;/a&gt; </code></pre> <p>The Selenium IDE plugin for firefox gives me the following selenium code for this:</p> <pre><code>driver.findElement(By.cssSelector("p.add")).click(); </code></pre> <p>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:</p> <pre><code>&lt;div id="cboxLoadedContent" style="display: block; width: 776px; overflow: auto; height: 653px;"&gt; &lt;div id="profielpagina_add"&gt; &lt;h2&gt;Voeg een vak toe aan je profiel&lt;/h2&gt; &lt;div class="lesboek_popup"&gt; &lt;a class="content" href="/olo-cleanjump/profiel/addvak/120776"&gt; &lt;img src="" alt=""&gt; &lt;/a&gt; &lt;p class="caption"&gt; &lt;a href="/olo-cleanjump/profiel/addvak/120776"&gt;Engels&lt;/a&gt; &lt;/p&gt; &lt;/div&gt; &lt;div class="lesboek_popup"&gt; &lt;a class="content" href="/olo-cleanjump/profiel/addvak/120786"&gt; &lt;img src="" alt=""&gt; &lt;/a&gt; &lt;p class="caption"&gt; &lt;a href="/olo-cleanjump/profiel/addvak/120786"&gt;Biologie&lt;/a&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>For the test I want to open the 'Biologie' link. Selenium IDE got me the following selenium code to do this</p> <pre><code>driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click(); </code></pre> <p>to select this biology link element. Based on this I wrote the following testcase:</p> <pre><code> 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); } </code></pre> <p>The part</p> <pre><code>driver.findElement(By.cssSelector("p.add")).click(); </code></pre> <p>actually was successful, so after this call the colorbox should be loaded. However the</p> <pre><code>driver.findElement(By.xpath("//div[@id='profielpagina_add']/div[20]/a")).click(); </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload