Click a Dropdown Menu Button using Watin - c#

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.

Related

Element deletion causes wrong click in Selenium

When selenium tries to click a button, web site deleting a div above, and selenium clicks the element under the element that I wanted to click.
I try to click with XPath, CSS selector, and the class name and none of them work. Also, I tried action chains to click but not worked.
And before clicking, I can confirm the selected element is the right element.
var element=driver.FindElements(By.ClassName("warning"))[0];
Debug.WriteLine(element.Text);
This writes the right element to the output.
-Here is the code By.ClassName:
driver.FindElements(By.ClassName("warning"))[0].Click();
The element under the right element does not have a "warning" class but it's still clicking on that element.
The page is basically like this:
<div id="maindiv">
<div class="the div that will delete"></div>
<button class="warning"></button>
<button class="second"></button>
<button class="third"></button>
<button class="fourth"></button>
</div>
here is how its looks
Basically, I'm trying to click the "warning" button but the "third" button receiving the click.
What should I do?
I solved the problem. First I deleted the div before clicking, then I clicked the button.
Here is the code:
var element = driver.FindElement(By.XPath("//[#id=\"app\"]/div[7]/main/div/div/div[2]/div/div/div[1]/div[1]"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].parentNode.removeChild(arguments[0]);",element );
var button=driver.FindElement(By.XPath("//*[#id=\"app\"]/div[7]/main/div/div/div[2]/div/div/div[1]/span[1]/span/button"));
((IJavaScriptExecutor) driver).ExecuteScript("arguments[0].click();",button);
`

how to click a button using the onclick attribute c# webbrowser?

I want to click on button that has the following html:
Bid
The problem is that the only attribute I can use is onclick, because there are more buttons on the site that use the same name as href, title and class, if I use any of these the click will be on more than one button, and I just want to click on this specific button.
if this button had an id, the code would be:
HtmlElementCollection elementButton = webBrowser1.Document.GetElementsById("Id");
elementButton.InvokeMember("click");
However, this button has no id. How to click on this button using the onclick parameter?

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();

Google Map not displaying after clicking button

I have been trying to hide Google Maps on my site (which is inside a div). I used the following in a "send" Button event called: function showPoint()
document.getElementById('GMap1').style.display = 'block';
But nothing happens when I click the send button which is suppose to execute this event.
I was able to hide the map with:
<div id="GMap1" style="height: 300px; width:300px; visibility:hidden;" ></div>
Only problem is displaying it.
you must modify the visibility, not the display:
document.getElementById('GMap1').style.visibility= 'visible';

Selenium to click on a javascript button corresponding to a text

I have a lot of buttons in my web page and that too are javascript buttons. All those buttons have same TagName, but different id. But I cant use ID since I cant predict which button has to be clicked.
Selenium will search for a content (Question here) and if could find the content, then it must click on the respective button. How can it be achieved?
Any comments would be really helpful and appreciated..
This will find a button based on the displayed text on the button and click it.
var loggout = driver.FindElement(By.LinkText("Logg ut"));
loggout.Click();
Or you can change it to;
By.Id()
By.CssSelector()
By.Name()
...

Categories

Resources