How to handle google search ajax data using selenium (Type some string in google search, do not press enter key and check matching string data in search text box) ? How to get this data using selenium RC/Webdriver ?
If you know that the action of some event (e.g. sendKeys, onClick, whatever) is going to trigger some event - like an Ajax request - you should be using waitFor until your condition is met (see the Advanced Usage guide).
To avoid supplying a brittle timeout threshold on your test, you may want to call this in a Poll implementation, say once every 500ms 10 times for example, and then pass/fail accordingly
FitLibraryWeb has some nice, clean abstractions for this, but you'd need to use Fitnesse of course
Thank u friends .. I am able to run a google search from selenium example code using firefox driver : http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example
Now i am trying to click on 'Change Location' available in left side pane after getting the search result but no luck. Code sample :
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
WebElement expandLocation = driver.findElement(By.id("expand_location_link"));
expandLocation.click();
Debug info:
In view source i am not able to see the element expand_location_link but is visible in element inspect section of firefox/chrome or after saving the page from browser to local system.
Related
I'm hard stuck with this one so any advice welcome!
Ive been trying to create a flow that goes to this website https://dlv.tnl-uk-uni-guide.gcpp.io/ and scrapes the data from each table in the Subject Areas drop down list. My knowledge of HTML is sketchy at best but from what I understand it's a dynamic html table that just refreshes with new data rather than going to a new url. I can extract the subject list as a variable and in my head i think i just need to add this to a UI selector action but despite numerous attempts i've got absolutely nowhere. Anyone got any ideas as to how i could fix this or work around?
Because it is not a conventional drop-down using the "Set drop-down list value on web page" doesn't work all that well.
You can use a bit of javascript and variables for this.
Hit F12 to show developer tools, you will see there is a list of hidden items with the class class="gug-select-items gug-select-hide" you will use this in the javascript.
Then add a 'Press button on web page' function and add the 'drop-down' element, which is a <div>
Then edit the element selector and change it to text editor.
then change the selector to make use of the nth-child(0) selector but use a variable for the index.
so it looks something like #gug-overall-ranking-select > div.gug-select-items > div:nth-child(%ddIdx%)
Use the "Run JavaScript function on web page" function to get the number of options available to the drop-down. (child elements)
The returned result is text, so convert it to a number that can be used in the loop.
function ExecuteScript() { /*your code here, return something (optionally); */
var firstDDlist = document.querySelector("#gug-overall-ranking-select > div.gug-select-items.gug-select-hide");
return firstDDlist.children.length;
}
In the loop each element will be pressed and cause the table to reload.
The table data extraction can then also be done in the loop, but that this code only shows the looping through the options.
The full flow 'code' (copy this and paste it in power automate).
WebAutomation.LaunchEdge.LaunchEdge Url: $'''https://dlv.tnl-uk-uni-guide.gcpp.io/?taxonomyId=36&/#gug-university-table''' WindowState: WebAutomation.BrowserWindowState.Normal ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 BrowserInstance=> Browser
WebAutomation.ExecuteJavascript BrowserInstance: Browser Javascript: $'''function ExecuteScript() { /*your code here, return something (optionally); */
var firstDDlist = document.querySelector(\"#gug-overall-ranking-select > div.gug-select-items.gug-select-hide\");
return firstDDlist.children.length;
}''' Result=> numberOfItems
Text.ToNumber Text: numberOfItems Number=> itemCount
LOOP ddIdx FROM 1 TO itemCount STEP 1
WebAutomation.PressButton.PressButton BrowserInstance: Browser Control: appmask['Web Page \'h ... sity-table\'']['Div \'gug-select-selected\''] WaitForPageToLoadTimeout: 60
END
It should end up looking like this:
Flow running:
With using Power Automate Desktop (PAD), the goal is to be a low-code solution. Of course knowing HTML is a bonus and will help you on tricky webpages or problems, but not knowing much is alright usually. I'm not really comfortable going to that web page you shared but you could try the below option.
PAD has a built in function in the action pane:
'Browser automation' > 'Web data extraction' > 'Extract data from web page'
Try using that and when asked to add UI Element select the table/dropdown list to see what information you get back. If that doesn't work you might need to try out JavaScript or another method.
I am working on xamarin.forms. I have a content page which contains one webview which load 3rd party url(www.xyz.com) site and one button in shell.
On button click event I am trying to get user input data using
webview.eval(javascript: var data = document.getElementById('first-name').value;alert(data)).
It works fine but due to void return type I could not store data in local variable and I have a customrender(webviewrender) but don't know on shell button click event how can I get userinput data from webview
Please suggest me how do I achieve this functionality.I do not want XLab-Hybridwebview.
You'll probably need to have the JavaScript code call out to the external code when the result is available. You could then wrap that whole process in a TaskCompletionSource to make everything nice and easy to use.
I am trying to automate actions and unable to select an element due to its dynamic nature.
I am running Selenium web driver on ruby and am trying to select value that is not present in page source.
<a class="linkOtherBrowser" onclick="addChangeStatusField('InitialSelectionPage');submitFormByAction('ChangeStep');return false;" href="#"><div class="processBarElement noSelected">
<div class="whiteBeforeProcessBarTitles"></div>Initial Selection</div>
<div class="endOfElementOfProcessBar"></div></a>
I am trying to select value "Initial Selection" from above.
Could anyone pls help out?
Thanks,
Abhishek
As the HTML is generated by Javascript, You need to inspect the DOM instead of viewsource and write the element locator code accordingly.
Note: In IE, Firefox or Chrome you can press F12 key to see the developer tools and use the inspect element option to check the DOM.
Whatever element is generated dynamically is added in your DOM. WebDriver has capability of clicking on elements are the visible on UI and hence if the generated element is visible to regular user's you can click on the element easily.
To do so, you need to identify the best selector for that newly generated click, could be xpath or css. Once you identify the selector you can consider clicking clicking using following code
WebElement element = driver.findElement(By.xpath("//a[#title='NAME_TITLE']"));
element.click();
OR
WebElement element = driver.findElement(By.css("a[title='NAME_TITLE']"));
element.click();
There are more options within your By.class on picking the element in best way
I am new to NUNIT and am stumped on how to close a dialog box.
The site I am experimenting with is Google Translate. Part of the code "clicks" on the "Send Feedback Link".
Below is the function I am using:
public void CloseModalWindow(string className)
{
WebController wPage = new WebController(driver);
wPage.waitUntilExistsByXPath(className);
wPage.waitUntilVisibleByXPath(className);
IWebElement clickButtonXPATH = driver.FindElement(By.XPath(className));
clickButtonXPATH.Click();
}
The basic logic is that I am trying to simulate is to click the "X" on the upper right hand side of the Google Feedback popup that appears.
Please note that:
The web driver is FireFox.
I am sending the XPath value (derived from Google Translate directly using FireBug) /html/body/div[3]/div/span[2].
I've also tried using the CSSSelector method instead of XPATH, sending the value span[class='modal-dialog-title'] into the function.
Nunit will in complete without any errors, but the popup does not close as I am anticipating.
Thank you in advance for your input and insight.
From your XPath I see that the "X" is not a natively clickable element - like <a> or <button> are. I experienced that calling Click() on such elements does not what one expects. Instead you could try using the action builder functionality which will simulate a general mouse or keyboard input. Replace
clickButtonXPATH.Click();
with
new Actions(driver).Click(clickButtonXPATH).Build().Perform();
I'm a QA, and I'm new to android automation as such, and I am having problem in automating the spinner / Dropdown related activities in my app. I am using Robotium 4.1 for my automation.
The Spinner in my app is implemented using actionbarsherlock. The Hierarchyviewer shows it as Popupwindow:SOME-RANDOM-ID. It looks like the implementation is internal to actionbarsherlock. After talking to the dev he tells me that it's a "non-visible" element. I don't understand what that means, because I can see the element.
Also, I can't find the methods mentioned in some of the other questions here.
I suppose the right way is to use solo.getViews(), and solo.getCurrentViews etc. but I don't know how to use the parameters in there, so whatever I tried didn't work.
Can someone guide me with a detailed example? (including how to give the parameters to getViews etc will be much appreciated.)
How to get number of items:
mSpinner.getAdapter().getCount();
How to click on specified item on spinner:
solo.pressSpinnerItem(indexOfSpinner, indexOfItem);
How to get current spinners:
ArrayList<Spinner> currentSpinners = solo.getCurrentViews(Spinner.class);
How to get spinner with specified index:
Spinner spinner = getView(Spinner.class, index);