I'm using Watir WebDriver. I'm new to ruby.
The following dropdown list is always present. It fails unless I precede it by sleep(1). The developer said that the dropdown is not populated until the previous controls are set.
Which of the Wait commands do I need for this? I think in Selenium I waited until the hidden contents of the list contained the value that I wanted, then I selected that value.
def enterCompany(company)
#browser.select_list(:id, "ddlCompanyName").select(company)
end
A question was just asked of me offline on this one, so I wanted to provide an updated answer for the latest Watir versions that avoids the deprecated #when_present method:
browser.select_list(id: 'ddlCompanyName').wait_until { |el| el.include? company }.select
You can use the when_present to wait until the option is present before selecting it. Basically, Watir will wait up to 30 seconds for the option to appear. If it appears sooner than 30 seconds it will proceed with the action (ie select). Otherwise, a timeout exception is thrown.
#browser.select_list(:id, "ddlCompanyName").option(:text => company).when_present.select
Note that the above assumes that company is the text of the option.
Another option is to wait for anything to appear in the dropdown.
#browser.wait_until{ #browser.select_list(:id, "ddlCompanyName").options.length > 0 }
Related
Using VSCode, I define a Task to compile my code.
Into the task, I define a problemMatcher to catch error(severity=error) or success(severity=info).
When I execute the task, if error match pattern, VSCode report it into a item of Problems Panel.
So, I read my error, place a correction on my code and re-start the task to compile. Now, there is no more error.
BUT how to remove the 'error' item from the Problems Panel ?
Is there a way to define a 'no'problemMatcher ? or a command to remove a item on panel ?
?
so, I found I need to define the problemMatcher.owner with a value (arbitrary).
If omitted, each execution set a different owner to the 'problem' item and then it do not delete previous 'problem' items.
Default 'external' if omitted seems not exact or not complete.
I discover it when I analyze the detail of Problems items (right copy message) from my problems and compare with working tasks/problemMatcher. The main difference was the owner value, unique on mine, same on working tasks/problemMatcher.
Is it normal for an XPath that was validated correctly in firepath and matched 1 node to fail to work in selenium webdriver (java)? I have a dynamic element and I have generated an XPath using the "contains" method which matched a single node that happens to be the same element I was looking for. In eclipse, webdriver throws a "NoSuchElementException" as it was unable to find the element. After you think you have mastered the tricks behind Xpath, some stubborn webelements uncover your flaws.
For the attached html, I have generated the below Xpath. Can anyone help generate an XPath or even CSS that would work?
//div[contains(#id, 'gwt-uid') and #aria-selected='true']
Yes. There is always a possibility of XPATH matching using Firebug (during development mode, where you visited page manually) may not identify during run time (browser launched using selenium). It is not because of Firebug showing wrong, but the HTML against which XPATH is using, may not be the same (might have changed, may be subtle changes).
I would strongly suggest pause (not stopping it) the execution during the run-time (one way is, using Thread.sleep(100) (100 seconds)) to give you enough time to evaluate your XPATH again to see the matches. post your observations.
XPATH seems fine to me.
Suspect may be, aria-selected set to false
I would think finding By.CssSelector would be easier:
driver.FindElement(By.CssSelector("div[id^='gwt-uid']"));
Though I would be concerned there may be other elements with ids prefixed with 'gwt-uid' because of what I assume is a dynamic unique id at the end of it. You could get the known closest parent (id='consumerTree') first to ensure you don't end up getting the wrong element. In C#:
IWebElement parent = driver.FindElement(By.Id("consumerTree"));
IWebElement element = parent.FindElement(By.CssSelector("div[id^='gwt-uid']"));
(Assuming you're using Java) If you are getting NoSuchElementException as your provided exception, There may be following reasons :-
May be when you are going to find element, it would not be present on the DOM, So you should implement WebDriverWait to wait until element visible as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#consumerTree div.v-tree-node[id*='gwt-uid']")));
May be this element is inside any frame or iframe. If it is, you need to switch that frame or iframe before finding the element as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
//Find frame or iframe and switch
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("your frame id or name"));
//Now find the element
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#consumerTree div.v-tree-node[id*='gwt-uid']")));
//Once all your stuff done with this frame need to switch back to default
driver.switchTo().defaultContent();
I currently have a HList set up so -browsecmd calls a subroutine when ever an entry is selected. I would now like to have a subroutine run when the user unselects an entry.
I have tried to google for this, but I have had no luck so far.
It's -browsecmd, too. The callback is executed whenever a user browses the HList. This also happens when unselecting an entry.
Using my #selected_items = $hlist->info('selection'); you can then access the currently selected items.
There is a complete example here (last example): http://www.perltk.de/tk_widgets/wtk_hlist.html
I would like to ask you, if is possible to renumber (automatically) my tags in testing script before every start (Test defined in include) ... no shortcuts. My goal is always actual and right number of step in log.
you can write a counter function. give a parameter at start to reset and whenever you called it, counter increment by 1
This is the first time I'm encountering GetLayoutObjectAttribute and I am having serious issues with it. My variable $web won't set. I think it's because PD_WebV isn't the right object name to refer to, but I don't know how to find the right object name. I can't find the objects name when I hit Edit Layout, so does anyone know how to find an layout objects name?
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
If[$Web="done"]
#execute if statements
After Edit:
After some troubleshooting, I found out that PD_WebV is the right object name to refer and it's refered to correctly, so my new question is why doesn't the script go to the line If[$Web="done"] and how could I fix it? Ss my If statement not evaluating something it should be? Is my $web variable never set to done or is the issue something completely different? Would the problem possibly have to do with my WebDirect sharing settings? Any guidance would help. Thanks.
After, After Edit:
So now that my application is getting past Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")], the variable $web only equals <HTML></HTML>. Does anyone know a way, without using javascript, to test the inside of the html tags?
Also, I printed the bounds of the webViewer PD_WebV that I can't locate on the layout but am referring to in the script. The bounds that are printed are different each time I run the script. Is the usual or unusual? My source is also about:blank so it doesn't look like I'm sourcing from a URL
Is my $web variable never set to done or is the issue something
completely different?
If you're doing:
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
then the only time
$Web="done"
will return true is when the web page loaded into your web viewer contains exactly the string "done" (in practical terms, that's never).
I have already suggested in a comment that you test for:
PatternCount ( $webpage ; "</html>" )
This is assuming you want the subsequent steps to execute only after the page has finished loading. The entire script would look something like this:
Loop
Pause/Resume Script [Duration (seconds): 1]
Set Variable[$Web; Value: GetLayoutObjectAttribute("PD_WebV";"content")]
Exit Loop If [ PatternCount ( $webpage ; "</html>" ) ]
End Loop
# execute statements
You might also want to add a counter to the loop and exit the script after n trials.
Ah, I reread your question.
To set the object name for your webviewer so that the GetLayoutObjectAttribute function works you need to set it in the Name field in the inspector when you have the webviewer selected.
e.g.:
After that your variable should populate.
Be aware
What it will populate with will be all of the html from the browser, i.e. not a boolean true/false liek your conditional suggests.
I'm not sure exactly what you're trying to accomplish, but to be able to determine a result from your web viewer you'll need to either parse the HTML to see if it's content contains what you're looking for or within the code you're setting the webviewer with, fire a javascript function that calls back to the FileMaker file using a FileMaker url.