WatiN finding link to click issue - c#

I am attempting do some automated testing using WatiN and C#. There is a link on the page as an image with the html code
<TD height=27 vAlign=bottom align=right>
<A href="paymentdetailsupdate.do">
<IMG border=0 src="/images/update.gif" width=64 height=21></A></TD>
I just want to click the link but this is proving to be very challenging.
I have tried using following code
cloaspage.Element(Find.By("href", "paymentdetailsupdate.do"));
but it does not seem to work. It times out looking for the element. I have absolutely no idea why. I also can't edit the HTML to add an id or anything like that. Any help is greatly appreciated.
EDIT: I forgot to add in that I can find the link by going through the tables,tablerows, tablecells etc but this is very time consuming and not practical in case of html changes.

Have you tried :
Link link = cloaspage.Link(Find.ByUrl("paymentdetailsupdate.do"));
link.Click();
Probably the same result but you should give it a try...

Related

Issue with a href link

I know it might look like a silly question but I am asking after spending a lot of time to figure it out.
I am trying to figure out from where the following link opening a window to download files
<h3>#Umbraco.GetDictionaryValue("ProductsPage_Download_CadDownload_Text", "CAD Downloads")</h3>
<a id="downloadcad" class="blue-btn icon-btn disabled" href="/cad-download" data-requestaction="down" target="_self"><i class="download cad"></i>#Umbraco.GetDictionaryValue("ProductsPage_Download_CadDownload_Link_Text", "Download CAD File")</a>
It seems like a simple link in a .cshtml page that is opening a "/cad-download" page/window. But the problem is there is no cad-download page/route/window or anything in project that I have but it work fine.
Any ideas would be really appreciated!
The A tag has an ID and a data attribute, and the URL doesn't contain an identifier. It looks like the link is being handled with JavaScript.
Search for references to the ID downloadcad or the data attribute requestaction and value down in the JavaScript included in the page and I expect you'll find the code that makes the download work.

Clicking on Href Button selenium

I have delt with an Href button in the past and didn't find it too hard, but this button is being a pain. I have tried clicking by xpath, class, and link text. None have worked. I know there are plenty of the same question out there, but most of them give answer's that I am already trying. Below is the code I have. The one thing I haven't tried is javascriptexecutor. I also have been clicking on it in the command line of chrome and it does work. Just can't get selenium too. It throws an element not found. Also I feel it is worthy to note that I did not find any IFrames that I need to switch to. The only things that concern me which maybe I do not have the knowledge of selenium to deal with is the HTML mentions header, main, section, div, ul, li , and a which I have seen all before except for ul and li. Thank you for any help someone provides.
wait.Until(ExpectedConditions.ElementToBeClickable(By.ClassName("card-header-link float-md-right"))).Click();
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div[1]/main/section[1]/div/ul/li[5]/a"))).Click(); //full xpath
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[#id='app']/main/section[1]/div/ul/li[5]/a"))).Click();
wait.Until(ExpectedConditions.ElementToBeClickable(By.LinkText("Security"))).Click();
HTML
<li data-v-91f16f3e="">
<a data-v-91f16f3e="" href="/security" class="">
<span data-v-91f16f3e="" class="icon icon-shield"></span>
<span data-v-91f16f3e="" class="text">Security</span></a>
</li>
try this xpath :
//span[text()='Security']/..
or
//span[text()='Security']/parent::a[#href='/security']
in code :
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[text()='Security']/.."))).Click();
but it is strange to know that By.LinkText("Security") did not work.
Update 1 :
try this css selector
div[class$='desktop'] li a[href$='security']
code :
wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div[class$='desktop'] li a[href$='security']"))).Click();
I see the href attribute value is lowercased security, not Security.
So, please try this:
wait.Until(ExpectedConditions.ElementToBeClickable(By.Xpath("//a[contains(#href,'security')]"))).Click();

Unable to find "Button" with Selenium in C#

I have got a problem with Selenium code to find a button which has only "Value" and "type", in inspection it looks like this:
<input type="sumbit" value="login" />
Image of inspection
I tried twice but neither line worked for me.
The lines:
1st solution:
driver.FindElement(By.XPath("//button[contains(text(),'Login')]")).Click();
2nd solution:
driver.FindElement(By.ClassName("submit")).Click();
Image with ERROR MESSAGE (second line error)
Can anybody help me, or at least point out what am I missing, because its getting pretty frustrating to find a solution for such common thing, I practiced this on tutorial pages and buttons were never a problem.
Please. (Sorry for my English)
P.s.: I checked the "similar questions and I haven't found the solution.
P.s.s: Guys, there is another one which I didnt try yet but I have 3 different lines of code, do you think one of them will work:
There is drop-down list and I want to select the last thing in the list...
driver.FindElement(By.XPath("//*[contains(., 'Process Data >>')]"));
driver.FindElement(By.Id("pdatasub")).Click();
driver.FindElement(By.XPath("//div[text()='Process Data >>']")).Click();
Inspection of the Drop-down list
Code for the opening of the last "button" in the drop-down list:
driver.FindElement(By.XPath("//div[text()='Final Values']")).Click();
enter link description here
Thanks guys for help !
You are using the wrong locator :
try this instead :
driver.FindElement(By.XPath("//input[#type='submit' and #value='Login']")).Click();
or
With ExplicitWaits
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[#type='submit' and #value='Login']"))).Click();
Your locator is wrong.
You can use this:
driver.FindElement(By.XPath("//button[#type='submit']")).Click();
or
driver.FindElement(By.XPath("//button[#value='login']")).Click();
or
driver.FindElement(By.XPath("//button[#value='login' and #type='submit']")).Click();
CSS Selector can be used as well similarly.
Also there are several possible issues:
You should add a wait before accessing that element. Otherwise you are trying to find an element while page is still not loaded. Expected conditions are the preferred way to do this with.
The element can be inside an iframe. If so you have to switch to that iframe in order to access elements inside it.

Adding a Textbox destroys Menu-Layout

I'm working on a little project with ASP and C#.
In my project I'm using a masterpage for the navigationbar on the top of my pages, looking like that:
The navigationbar contains some normal navigation-points and one to log out with float: right;
On all of my diffenrent pages this works excepted for one.
The only difference is, that on this special page I have some textbox-elements like this:
<asp:TextBox ID="tbTOP1sum" runat="server"></asp:TextBox>
As soon as I only enter one of this textboxes my navigationbar looks like that:
It doesn't matter what sort of element im adding, everything is okay, excepted with this textboxes.
I noticed that this only happens in Google-chrome, not with Firefox and not with Internet-Explorer or Edge. Another thing i found out is, that disabling and enabling the CSS-rule in Chrome-Page-Inspector fixes the problem.
I have no idea what to do...
Thanks in advance for your help!
I have the same issue sometimes. When you change it in the inspector go into your code and make the same change and save/build, go to the web browser and do a hard refresh with "ctrl+F5". If it still does not work, wrap your logout a link in a div and then call it in CSS. Set the position to relative, and then put the top: -55px;
It finally turned out, that adding display: inline; to the of the navigationbars <ul> is all to do.
Another way is to do it with table columns. One for the normal content and one for the logout.
Thanks for the other answers!

Unable to decipher DIV tag with CSS

I've got this DIV tag that has a class definition in it.
<div class="clear hideSkiplink">
I've searched the entire project, but I can't find this class anywhere by using the text search feature.
Currently, the DIV is too wide, and I need to trim it down a bit.
Whenever I remove the class="clear hideSkiplink" reference, the DIV tag immediately grows much too large.
I inherited this project after the website developer left. I'm good with C# and WinForms, but not really this web stuff.
Could someone help me out, please?
Solved!
I found .clear { clear: both; } burried in the file StyleSheet.css, but I could not find the hideSkiplink word anywhere in my project.
So, I took the hideSkiplink word off, and the rendered page did not change in the browser.
Apparently, all I was seeing was controlled by the one clear word in the DIV tag.
My tag now reads:
<div class="clear">
Thanks, JLevett!
'clear' and 'hideSkiplink' are too different classes, not one.
Try searching for those individual phrases within your project.
if you have firebug, go to HTML tab, find your element and click on int, I made you a screen of this page as an example, the red circles show the class names and the green circles show you the css source file. You might as well ctrl+click on the source files and they open in a new browser window :)

Categories

Resources