How to click this button using Selenium C#? - c#

<div class="mdl-align"> == $0
: :before
<button class="fp-upload-btn btn-primary btn">Upload this file</button> == $0
: :after
</div>
The above codes are from a website, however I am unable to click this button despite trying multiple attempts. Im using selenium with C# to do an automation testing.
What this button does, is to simply submit a form.

Try to use xpath locator to click on Upload this file button.
driver.FindElement(By.XPath("//button[contains(text(), 'Upload this file')]")).Click();

Related

Get file link on ng-click event selenium

Hi is there any way to get link for file, when I click on Download button browser start to download file.
I have following html button tag.
<button type="button" ng-click="vm.handleClick(vm.item[1])">Download</button>
When I use this it only download file, is there any way to get link from ng-click event?
executor.ExecuteScript("arguments[0].click()", webElement);

C# Selenium Button in a Span Class XPath (Amazon.com)

I am trying to create a proper XPATH syntax in C# to click on a download button from the Amazon business website. Everything I have tried is unable to find the button. Here are some of the things I've tried:
driver.FindElement(By.XPath("//button[#type='submit']")).Submit();
driver.FindElement(By.XPath("//span[contains(#class,'a-button-inner')][contains(text(),'downloadCSV_button-announce')]")).Submit();
driver.FindElement(By.XPath("//span[contains(#class,'a-button-inner')][contains(text(),'Download CSV')]")).Submit();
Below is the source code from the Amazon page. Can anyone help me to design the proper XPATH query to click this download button? Thank you.
<h1>Amazon Business Analytics</h1>
<div class="a-row a-spacing-medium a-grid-vertical-align a-grid-center">
<div class="a-column a-span12">
<span class="a-declarative" data-action="aba:download-csv" data-aba:download-csv="{}">
<span id="downloadCSV_button" class="a-button aok-float-right"><span class="a-button-inner"><input class="a-button-input" type="submit" aria-labelledby="downloadCSV_button-announce"><span id="downloadCSV_button-announce" class="a-button-text" aria-hidden="true">Download CSV</span></span></span>
</span>
You should try using WebElement#click() to perform click on element instead as below :-
driver.FindElement(By.CssSelector("input.a-button-input[aria-labelledby = 'downloadCSV_button-announce']")).Click();
Or if span element is clickable try as :-
driver.FindElement(By.Id("downloadCSV_button-announce")).Click();
Or
driver.FindElement(By.Id("downloadCSV_button")).Click();

Click a Dropdown Menu Button using Watin

I am testing a website using Watin in the page there is dropdown menu button like if I find that button and click it clicks the entire button and selects the first Option in the menu but I want to click the V of the button to show the dropdown menu(div) and select the option from it the code I had tried to click the button
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent("onmouseover");
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent(" Onmousedown");
ff.Button(Find.By("aria-describedby", "x-auto-456")).Click();
the Button HTML
<button class="x-btn-text" style="position: relative; width: 16px;" type="button" tabindex="0" aria-describedby="x-auto-456">
Edit:
I had tried to find the co-ordinates of the Image in the button and then click it with the below code but its slightly not working kindly any one point me how to click the button and show the div Instead of selecting a option automatically,
NameValueCollection eventProps = new NameValueCollection();
eventProps.Add("clientY", "240");
eventProps.Add("clientX", "240");
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent("onClick",eventProps);
You are not finding the button correctly:
Button button = ff.Button(Find.ByClass("x-auto-457"));
You need to find the button by its class name. Be aware that will find the first <button> or <input type="button|submit|reset"> element with that class name. If you still aren't getting the correct button, check to see how many buttons on the page have x-auto-457 for a class attribute value.

Windows form application clicking an "onclick=return"

So im trying to make an script that does the BFH (in a game) auto but when it clicks on the sumbit button the webbrowser opens up an confirm box (code element inspecting showed down). So how do i make it so my application clicks the ok on the confirm box
The webbrowser opens up a box and the application has to click the ok button
Sorry if i explain it strange its because my english isnt that great
this is the button it clicks
<input class="submit" type="submit"
onclick="return verifyTransport('Are you sure you want to transport €…,000 to the team deposit?\nThe trip will take 25 minutes.');"
value="Transport € 5,000,000"
name="dr_transport_money"></input>
Example of what it shows(cant show the real one can only do that once a day):
Try This:
private IWebElement element;
element = driver.FindElement(By.XPath("//input[#name='dr_transport_money']"));
element.Submit();
driver.SwitchTo().Alert().Accept();

How can I create in C# a page to response to another one?

How can I create in C# a page to response to another one? So when you press the button,login form opens in a new widow(browser tab or widow), and as you login... the form automaticaly refresh the first page.
Like the Open ID form. You press the (Connect with Facebook) button it opens a new window with the login form and then it refreshes the the website where u pressed the button.
Sorry for my English!! :) & please help!
You open a new window from a button click like this:
Markup:
<asp:button type="button" id="btnLogin" runat="server" Text="Click me" OnClientClick="javascript:window.open('newPage.aspx'); OnClick="ServerSideCode" />
Or with a regular HTML button:
<input type="button" id="btnLogin" value="Click me" onclick="javascript:window.open('newPage.aspx');" />
On newPage.aspx you define a function to auto close the current form and reload the parent form. Something like:
function closeMe()
{
window.parent.location.reload();
self.close();
}
And on server-side, when you handle your button Click event, you add this line all the way at the bottom depending on whether the process was successful. Example:
if(loginSuccessful)
ScriptManager.RegisterStartupScript(this.GetType(), "whatever", "closeMe();");
Learn more about AJAX. And technically, a C# code deal with pages (it may however handle HTTP requests & replies).
you can use ( if you open a new window) the opener object.
and you can also make use of the PostBackUrl
also you can make use of form1.Action

Categories

Resources