im building roulette bot, im finding element by xpath i can get its class attiributes etc. but i cant click on it. its always clickable (bot finds ifrime and then finds element and clicks its working but this website gamescreen in iframe>iframe bot can find button but not clicking)
firefox.SwitchTo().Window(firefox.WindowHandles.Last());
var DBViFrame = firefox.FindElement(By.TagName("iframe"));
firefox.SwitchTo().Frame(DBViFrame);
DBViFrame = firefox.FindElement(By.TagName("iframe"));
firefox.SwitchTo().Frame(DBViFrame);
var dataEntryButton = firefox.FindElement(By.XPath("//*[name()=\"svg\"]//*[name()=\"g\"]//*[name()=\"rect\"][" + num + "]"));
dataEntryButton.Click();
Is firefox your WebDriver? If so, maybe try execute_script and see if that works?
firefox.execute_script("arguments[0].click();", dataEntryButton)
Related
I am trying to automate the scheduling of pinning items to Pinterest using Tailwindapp.com. I am using a console app in .NET (C#) with Selenium Chromedriver. I start up the browser and enable the tailwind extension and login to tailwind. Then I go to the site I am trying to pin images from, get to the product page, search for the button and attempt to click it. That's where it falls apart. The 'Schedule' button in Tailwind appears over all images on the page as you hover. When I do an XPath search, it only returns a single button for the whole page (the console line below shows 1).
public static void ClickScheduleButton(IWebDriver driver) {
// get all the buttons and then use the first one
IList<IWebElement> buttons = driver.FindElements(By.XPath("//*[#id='tw_schedule_btn']"));
Console.WriteLine("Number of items found: " + buttons.Count());
IWebElement scheduleButton = buttons.ElementAt(0);
Actions actions = new Actions(driver);
actions.MoveToElement(scheduleButton).Click().Perform();
}
On the perform method, I get the following error: OpenQA.Selenium.WebDriverException: 'javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
From what I've read, this seems to mean that there are more than 1 element but I seem to have ruled this out with the number of buttons found. I have attempted to do a wait to make sure it's available but I do not believe that is the issue.
I have tried to find an example just trying to do this with a Pinterest button because in theory it would be the same logic but I cannot find anything for that either.
My assumption is that it's a problem just getting the button to appear on the correct image? But that's just a guess.
If I'm understanding this correctly you want to click the button who appears in when you hoover the mouse in the image.
If you can hoover the mouse and wait until the expected xpath appears should solve it.
protected virtual void HooverMouse(By element)
{
Actions action = new Actions(driver);
action.MoveToElement(driver.FindElement(element)).Build().Perform();
}
The element will be the first image you have, so you must change your driver.findelements("the button") to the "images" and loop arround this.
In pseudo code will be:
Hoover(image) -> WaitButtonAppears -> ClickButton
I have written this code
List<IWebElement> CountingAds = driver.FindElements(By.XPath("//a[#onmousedown='return google.arwt(this)']")).ToList();
for (int i = 0; i < CountingAds.Count; i++)
{
Thread.Sleep(5000); CountingAds.ElementAt(i).Click(); driver.Navigate().Back();
}
for clicking the Ads which appears while we search on the Chrome Browser but it just click the first Ad Successfully but next time it gives this error
enter image description here
someone help me out with this problem i am getting too frustrated guys.
You are getting stale element reference exception, which comes when the element you are operating on is no longer present or is an old element and that's why it is working only the first time and not after that.
So to solve this problem, you need to fetch fresh element everytime after you click on one ad.
For example(i am using java so please convert the code to whichever language you are using):
List<WebElement> CountingAds = driver.findElements(By.xpath("//a[#onmousedown='return google.arwt(this)']"));
CountingAds.get(0).click();
And now again fetch the webelement list and again click on the element like we did it by the above code. This would solve your problem.
I am trying to automate sharepoint site new item form but what ever method i try it is showing not found.
I tried switchTo() to a new iframe, window...
Tried this code which finds the outer content
IWebElement table1 = WebElement.FindElement(By.XPath("//table[#class=\"s4-wpTopTable\"]"));
int table1count = WebElement.FindElements(By.XPath("//table[#class=\"s4-wpTopTable\"]")).Count;
MessageBox.Show(table1count.ToString());
above code displays the table count as 2. Going beyond this element does not show any element.
And I am using IE as the browser.
I used Xpath and could identify till the red mark and it does not identify beyond that.. i am trying to identify the elements marked in green.
var iframecount = driver.FindElement(By.XPath("//html/body/form/div[8]/div/div[4]/div[2]/div[2]/div/div/table/tbody/tr/td
Here is the xpath is used taken from FireBug
var iframecount = driver.FindElement(By.XPath("//html/body/form/div[8]/div/div[4]/div[2]/div[2]/div/div/table/tbody/tr/td/div/span/table/tbody/tr/td[2]/span/span/input"));
i have found answer for this...
Sharepoint New item form (i.e modal pop up) has 3 iframes without id or name so switching to iframe using the below code works
driver.SwitchTo().Frame(2);
i.e frames start from 0 index.
I am trying a select a text from the Dropdown Menu using Selenium webdriver in C#
It is working perfectly with Chrome browser, but not with Firefox. Could any one help me to fix this.
The code I am using is given below.
public void SelectCountry1(string country)
{
var countryDropDown = Driver.FindElement(By.XPath(xpathidofthecountrydropdown));
countryDropDown .Click();
//Driver.FindElement(By.XPath(xpathidofthecountrydropdown)).Click;
var selectElement = new SelectElement(countryDropDown);
selectElement.SelectByText(country);
}
I am able to call this function and this is executing successfully without any error messages. I am not able to select the expected keyword eventhough it exists.
Currently I am having a workaround of Clicking on the same id twice and that makes the code to work. With the commented section uncommented But I dont think that is correct workaround. Let me know your thoughts on this.
Thanks
Yah, it doesn't work well with Firefox. I had to use this as a workaround using jQuery. Feel free to modify this code with regular JavaScript if you don't have jQuery on the page.
public static void SetDropdownSelectedOptionByText(IWebDriver driver, string tagId, string newText, int sleepTime)
{
// not working when selecting client id of certain types of ASP.NET user controls
//new SelectElement(driver.FindElement(By.Id(tagId))).SelectByText(newText);
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("$('#" + tagId + " option:contains(" + Element.NonNullValue(newText) + ")').attr('selected', 'selected')");
js.ExecuteScript("$('#" + tagId + "').change()");
System.Threading.Thread.Sleep(sleepTime); // wait for dependent dropdown to load its values
}
Normally the select class handles the selection without you even clicking the drop down. It should work both in FF and Chrome, Ie has some other issues with Select. Try not to click the drop-down button at all. If Select class does not function the way it suppose to try clicking and navigating options sending up down keys and then pressing enter.
I'm trying to build my first test with selenium and got a problem.
I'm searching for a element, no problem. I can click on it, get the
text in the element... every thing works fine.
But double click on the element just doesn't work. Selenium
clicks in the wrong location. I made a screenshot of this situation:
Screenshot
To find the row i use xpath and search for the text in the cell, but this text is unique(I checked it)
private readonly string _identityPath = ".//td[.= 'All Employees']";
...
mainPage.FindElement(By.XPath(_identityPath)).Click(); //Works(dotted box)
Actions builder = new Actions(mainPage);
IAction doubleClick = builder.DoubleClick(mainPage.FindElement(By.XPath(_identityPath))).Build();
doubleClick.Perform(); //wrong location/element
/*
Actions action = new Actions(mainPage);
action.DoubleClick(mainPage.FindElement(By.XPath(_identityPath)));
action.Perform(); *///wrong location/element
This page is in an iframe and the grid is a dojo component... maybe the problem
comes from there. Any ideas whats wrong? I have no idea where this is coming from. :/
Greets
It is common issue that Actions builder does not work.
Using JavaScript should help - find answer in this thread:
Selenium 2/Webdriver - how to double click a table row (which opens a new window)
If the element is in an iframe, you need to switch to that iframe in order to interact with the element.