I am in middle of a selenium application development using C#. I have a drop down menu on a webpage. I want selenium to click on the exact name after clicking the drop down menu. I am successful on clicking drop down menu now and I can view the titles or options on that menu.
What I want is that I need selenium to click on the title based on what the user gave when the application is first opened. Actually the menu button is not visible, but when I make mouse hover the name, it is visible.
I have tried
var menu = driver.FindElement(By.ClassName("ms-vb"));
SelectElement sel = new SelectElement(menu);
sel.SelectByText(text);
where text is the user entered text. While running the app it throws an error like
"Element should have been select but was img"
How can I solve this??My task is onhold due to this..
Any comments will be really appreciated..
Thanks
HTML
I hope this is the code that you require:
<table cellspacing="1" cellpadding="0" height="100%" onmouseover="OnMouseOverFilter(this)" class="ms-unselectedtitle"
sortfields="SortField=Unify%5fx0020%5fApp&SortDir=Asc&View=%7b696D6B29%2d5A5D%2d47F3%2d97CF%2dECBFDD1E2CE8%7d"
resulttype="" fieldtype="Lookup" displayname="Unify App" ctxnum="1" name="Unify_x0020_App" filterable="" filterdisable=""
sortdisable="" sortable="" style="width:100%;" id="msomenuid2">
<tbody>
<tr>
<td width="100%" nowrap="nowrap" class="ms-vb">
<a sortingfields="SortField=Unify%5fx0020%5fApp&SortDir=Asc&View=%7b696D6B29%2d5A5D%2d47F3%2d97CF%2dECBFDD1E2CE8%7d"
onclick="javascript:return OnClickFilter(this,event);" href="javascript:" title="Sort by Unify App"
onfocus="OnFocusFilter(this)" id="diidSortUnify_x0020_App">Unify App
<img width="1" border="0" height="1" alt="Use SHIFT+ENTER to open the menu (new window)." class="ms-hidden"
src="/_layouts/images/blank.gif" /></a>
<img border="0" alt="" src="/_layouts/images/blank.gif" />
<img border="0" alt="" src="/_layouts/images/blank.gif" />
</td>
<td style="position: absolute; right: 1px;" class="">
<img width="13px" alt="Open Menu" style="visibility: hidden;" src="/_layouts/images/menudark.gif" />
</td>
</tr>
</tbody>
</table>
If it is not a normal element the SelectElement class will not work.
This is how I deal with javascript dropdowns:
//Click on the dropdown
driver.FindElement(By.ClassName("ms-vb")).Click();
//Wait for the result list to appear
wait.Until(x => x.FindElement(By.LinkText("Target link to click")));
//Click on the result you want
driver.FindElement(By.LinkText("Target link to click")).Click();
If the result is not a link you should use xPath to locate it by its text. Ex.
driver.FindElement(By.XPath("//*[text()='Target text']")).Click();
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.