first time working correctly. second time error through "cannot click on element".

791 views
Skip to first unread message

Vasanth Kumar

unread,
Nov 6, 2012, 1:46:50 AM11/6/12
to seleniu...@googlegroups.com
Hi Experts,
                  I have one issue in selenium webdriver. I am using data driven testing in web driver. Problem is for loop first time executed successfully. second time confirmation message "Ok" button through error "cannot click on element". but element is visible. please help to fix this issue.

Here is my HTML Code:

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="display: block; z-index: 1010; outline: 0px none; height: auto; width: 300px; top: 247px; left: 522px;" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog-confirmSL2">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<div id="dialog-confirmSL2" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 67.4667px;">Site location saved successfully.</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
<span class="ui-button-text">Ok</span>
</button>
</div>
</div>
</div>

Here is my WebDriver Code

foreach (DataRow dr in mydataset.Tables["sitelocation"].Rows)
            {
                WebDriverWait wait1 = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                wait.Until((d) => { return d.FindElement(By.Id("lblCreatenew")); });
                driver.FindElement(By.Id("lblCreatenew")).Click();

                wait.Until((d) => { return d.FindElement(By.Id("TxtSiteLocation")); });
                driver.FindElement(By.Id("TxtSiteLocation")).Clear();
                driver.FindElement(By.Id("TxtSiteLocation")).SendKeys(dr[0].ToString());

                driver.FindElement(By.XPath("(//button[@type='button'])[3]")).Click();

                wait.Until((d) => { return d.FindElement(By.Id("dialog-confirmSL1")); });
                driver.FindElement(By.XPath("(//span[text()='Yes'])")).Click();

                wait.Until((d) => { return d.FindElement(By.Id("dialog-confirmSL2")); });
                driver.FindElement(By.XPath("(//span[text()='Ok'])")).Click();
            }

Regards,
Vasanth

musaffi

unread,
Nov 6, 2012, 2:47:52 AM11/6/12
to seleniu...@googlegroups.com
Helooo....

Selenium Driver is no able to find the element here for the second time , because the element must be a dynamic one here ...
to confirm this do onething here...

Inspect the page elements , open the 'Xpath checker' ( a plugin to firefox).... write the Xpath of your element.... it will find the element ... copy the Xpath...

Refresh your page.... use the same Xpath and try to find it ... it will not find it .. if its dynamically changing.... this will confirm the problem here...

Solution is write a proper dynamic Xpath for the element.... it will never fail :)


~Musaffir...

Vasanth Kumar

unread,
Nov 6, 2012, 3:54:09 AM11/6/12
to seleniu...@googlegroups.com
Hi Musaffir,
                      My selenium code using find element Id "dialog-confirmSL2". this is static id. then i am using span tag to search Ok text. div have dynamic id. but i am not using div for find element. please correct i am wrong.

Regards,
Vasanth.




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/Zcsv6HROT20J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mike Riley

unread,
Nov 8, 2012, 1:03:01 AM11/8/12
to seleniu...@googlegroups.com
A span element is not clickable.  The button is.  So you need to click on the button.

You had an extra ')' in that XPath, too.  Here is one that I think will work:
driver.FindElement(By.XPath("(//span[text()='Ok']/..")).Click();

Mike
Reply all
Reply to author
Forward
0 new messages