Selenium WebDriver unable to find element that is clearly there - html

Ok, this statement is giving me an error:
new Select(driver.findElement(By.id("870"))).selectByVisibleText(reason);
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"870"}
Command duration or timeout: 1.02 seconds
And I have tried finding it by xpath, and id, and I know for a fact its there with the id 870. I have tried putting in sleeps to make sure it is loaded too.
Thanks in advance.
I am using version 2.5 with Firefox.
Element is
<select id="870" class="ui-widget-content reactor alias_reason" data-bind="options: questionValueGroup.questionValues, optionsText: 'qu…: properties(), setSingleSelected: $parent.providerAnswers()" paid="37" group="6" style="background-color: #FCFDFD;"></select>
edit 2: I figured it out guys, I just used chromes xpath selector tool and it gave me a different xpath that works.

I am thinking that the fact you have an id which starts with a number is confusing Selenium. W3C standards say that Ids cannot start with numbers, therefore try the following;
new Select(driver.findElement(By.css("[id='870']"))).selectByVisibleText(reason);
or
new Select(driver.findElement(By.xpath("//*[#id='870']"))).selectByVisibleText(reason);

Related

Using groovy script on Katalon to click on row of grid

With groovy script on Katalon, I want to click on first row of grid but it is not working and it shows error (error.png with Option1 mentioned below) in console.
I have tried by targeting different element's xpath of row but it seems click() event is not being recognized. Also, added wait and waitForPresentElement but did not work.
Following are three options I tried so far but none of them worked.
Groovy on Katalon:
Option 1:
WebUiCommonHelper.findWebElement(By.xpath("//div[#class='dgrid-row dgrid-row-even ui-state-default']/table/tr/td/span[#class='dijitIconFlag dijitFixedMatterIcon']")).click()
Option 2:
WebUiCommonHelper.findWebElement(By.xpath("//div[#class='dgrid-row dgrid-row-even ui-state-default']/table/tr/td[contains(#class,'dgrid-cell dgrid-cell-padding dgrid-column-0-')]").click()
Option3:
WebUI.click(findTestObject('Object Repository/Page_Law Practice Management Software CosmoLex/td_Client Funds-Trust_dgrid-cell dgrid-cell_865aa6'))
Source code:
Source code is in xPath.jpg.
Expected:
The row should be selected/clicked.
//table[#class="dgrid-row-table"]//tr//td
Use this as xpath,
and click by this manner.
Hope it will help you.
List<WebElement> objects = WebUiCommonHelper.findWebElements(findTestObject('***put xpath url here***'), 30)
WebUI.delay(1)
objects.get(0).click()

angular 5 select IE no value

I am currently having an issue with Angular.X (Tested with A5 & A6). It appears when using a "Select" within the html, Internet Explorer doesn't bind appropriately with ngModel. I've tested with Chrome and Edge and they work fine, When trying to use this combination in edge- the select never gets set as its default value (The value that is assigned within the model/property its bound to). So the page will load with empty values in the select. I've tried searching but have not had any luck finding an answer how to fix this. 9/10 of the posts I find when searching for this are related to AngularJS. Which always makes troubleshooting fun!
Here is a bit of the code as to how I am doing this:
HTML:
// The repeater is up top somewhere and looks like this:
// <tr *ngFor="let i of this.imgArr">
<td class="ImageCell">
<select [disabled]="this.ApplyingChanges" [(ngModel)]="i.ImageType" class="form-control" (change)="this.ChangeInput(i)">
<option>Part</option>
<option>Model</option>
</select>
</td>
TS Class:
export class PartImage{
public ImageType = 'Part';
The above code is broken up to show what matters.
Thanks for the help in advance!
Sorry I actually resolved this.
After tinkering around, I discovered: With Edge and Chrome, an "option" is not required to have the attribute "value" and uses the label by default. With Internet Explorer this is not true and requires that attribute (Or ngValue) to work correctly.

Capybara Ambiguity Failure select list

I am getting
Ambiguous match, found 2 elements matching css ".active-result" with text "jeeny"
<select style="display: none;" class="form-control input-sm" id="column" name="column"><option value="">Select</option><option value="UPPER(supervisor.name)">jeeny roat</option>
<option value="UPPER(suprem.code)">jenny</option>
<option value="UPPER(officer.code)">carl</option></select>
it is able to detect jeeny roat bu not jenny
chosen_select('jeeny', from: 'column')
chosen_select('jeeny roat', from: 'column')
Also not able to detect value select select list is hidden
chosen_select is a helper method
Chosen::Rspec::FeatureHelpers using instance method
def chosen_select(value, *args)
opt = args.extract_options!
input = chosen_input(opt)
args.unshift(value).uniq.each { |item| chosen_select!(input, item) }
end
I did some searching, and am going to guess that you're using the chosen-rails gem which provides the chosen_select method defined at https://github.com/tsechingho/chosen-rails/blob/fb28dfcf0dca5ef49344a8d961b733b5bd96449f/lib/chosen-rails/rspec.rb This ends up calling chosen_select! which should work due to the specifying of :prefer_exact for the matching method at https://github.com/tsechingho/chosen-rails/blob/fb28dfcf0dca5ef49344a8d961b733b5bd96449f/lib/chosen-rails/rspec.rb#L66 . Since it's not working for you and the fact that you're still on Capybara 2.1.0 I'll guess you're also on a really old version of chosen-rails from before the matching method was specified. If that is the case, and you can't upgrade the gem, you can try specifying a Regexp to force the text find into exact mode
chosen_select(/\Ajeeny\z/, from: 'column'

How do I use the new `console.log()` output of Chrome?

Chrome 24 has a new way of outputting objects in console.log().
For example, console.log($("p")); on this jsFiddle example outputs this insanity:
▼[<p>, <p>, <p>, prevObject: jQuery.fn.jQuery.init[1], context: #document, selector: "p"]
► 0: <p>
► 1: <p>
► 2: <p>
► context: #document
length: 3
► prevObject: jQuery.fn.jQuery.init[1]
selector: "p"
► __proto__: Object[0]
I can see that it puts the collection of DOM elements at the beginning. But if you try to expand even a simple <p> tag that is mostly empty, it throws up all over you:
▼ 0: <p>
accessKey: ""
align: ""
► attributes: NamedNodeMap
...
[stopping here for sanity's sake]
So how do I use all this information? My first instinct is to tame it down to how it used to look, but on second thought, there really is a lot of info in there that I might want to have access to. But I'm having a hard time understanding what I'm looking at. Much of it looks like jQuery values. Is this a list of every jQuery value that the object has (or doesn't have)?
Then there's the whole issue of the ► context: thing and the ► __proto__: thing. Once you start drilling down in __proto__ you will never stop. I think it goes infinitely down!
How can I begin to learn how to use this new output?
EDIT:
I actually just realized that I'm still using Chrome 23, this isn't something that was introduced in 24. Someone in this thread said it was a Chrome 24 issue, but maybe it's new in 23? At any rate, I only just recently started noticing this on jQuery objects.
EDIT 2: If you're just looking for how to log the old way, try this: (hat tip)
console.log.apply(console, $("div"));
In your demo fiddle, you are logging NodeLists or HTMLCollections. Each of the elements within a NodeList is represented as a numeric index 0, 1, 2, etc. 0 being the first in the NodeList if any elements exist in it.
When you expand the Elements you see all available properties of an HTML Element as defined in DOM Core 3 specification. Refer here for more information about this http://domenlightenment.com/#3.2 and for a list of all properties and their purposes go here: https://developer.mozilla.org/en-US/docs/DOM/element. None of this is new in Chrome.
What is new in the latest Chrome version is the top level logged object, so if you just opened the console and typed:
console.log(window)
Which for me when I just did it logged a preview of what the expanded window object it provides when logging it. So for example, you should see something like:
Window {is_minor: 5, bmi_ie6: false, careers_adselector: "div.hireme, div#hireme"...}
Other NodeLists properties listed below the Elements of the list:
context - the context of the selection - http://domenlightenment.com/#4.4
length - the number of Elements in the HTMLCollection
selector - the selector used to select the Element or NodeList
__proto__ - An Object's __proto__ property references the same object as its internal [[Prototype]] (often referred to as "the prototype"), which may be an object or null (in the case of Object.prototype.__proto__). For more info on this refer to: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/proto
I modified the fiddle slightly and should show the preview of the objects when you view the console http://jsfiddle.net/jaredwilli/H3YWq/2/
You can't really get rid of any of these things either, they're a part of the DOM and will exist always otherwise the NodeType of what you're looking at will be something other than an ElementNode.
I'm just as annoyed as you are with this change. I know this isn't ideal, but it will hopefully help you a little bit.
console.log($('p')[0]);
You may have seen that solution before, and then found it didn't work if you were in a loop for instance:
$('p').each(function(){
console.log($(this)[0]);
});
That doesn't end up giving you the result you were used to either, so I had to use ['context'] instead of [0] like this:
$('p').each(function(){
console.log($(this)['context']);
});
Again, I'm looking for a better solution myself, but I thought I'd share with you what I've found.
You want first element so use [0]
As another option, check out Firebug in Firefox. I know, I love chrome too and use it every day, but Firebug is a great plugin and I've never had an issue with it.

Why selenium locating element by Xpath failed in IE, but it works wll in firefox?

I have my selenium automation test scripts run in firefox, and it works well.
Now I want to run the scripts in IE, it seems it failed on the step of locating an element in GUI. It seems selenium can't find the element in GUI while firefox can easily find it.
String servicenameidtext = "//table[#id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td";
Selenium.getText(servicenameidtext );
In fact, the scripts is recorded by selenium-IDE, and I have check about the Xpath, I think there is no problem of the element. But why selenium failed on this step in IE?
Could anyone tell me the reason? And how to solve the problem when running test in IE?
Thanks a lot!
I want to locate the element "alarmlm" from the GUI by
String servicenameidtext = "//table[#id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td";
P.S: The html of the part:
<tbody><tr class="form-title"><td colspan="3"><img src="img/minus.png" title="-" alt="-"> <b>Software Information</b>
</td></tr><tr><td><div id="release_hostsSoftwareInformation_internal">
<table id="release_hostsProcesses_list" border="0" width="100%" class="Processes_list"><tbody>
<tr class="title-column"><td><b>Service Name</b></td><td><b>Summary</b></td><td><b>Description</b></td><td><b> Version </b></td><td><b>Release</b></td><td colspan="2"><b>Installation Date</b></td></tr><tr><td>alarmlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>annlabclient</td><td>Annlab Client</td><td>Annlab Client</td><td>5.0.13</td><td>23</td><td>Wed 10 Nov 2010 04:23:57 AM CST</td></tr><tr><td>annlabserver</td><td>Annlab Server</td><td>Annlab Server</td><td>5.0.13</td><td>23</td><td>Wed 10 Nov 2010 04:23:57 AM CST</td></tr><tr><td>recoveryalarmlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>recoverystatlm</td><td>mpm</td><td>MultiPlatformManagement tools</td><td>4.0.12</td><td>5</td><td>Wed 10 Nov 2010 04:23:52 AM CST</td></tr><tr><td>mrfctrl</td><td>MRF Controller</td><td>mrfctrl - including sipproxySubsystem</td><td>1.4.0.5</td><td>1</td><td>Wed 10 Nov 2010 04:24:00 AM CST</td></tr></tbody></table></div></td></tr></tbody>
Thanks to all, the problem is solved. The cause is: the html in firefox and IE are not the same. Strange.
Maybe, due to a default namespace?
The error explanation is in the data you haven't shown us -- what about providing the (x)Html text?
UPDATE:
Now the OP has provided the source (x)Html document. The provided XPath expression:
//table[#id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td
doesn't select the required element simply because a td is never a child of another td, but this is exactly what this XPath expression is looking for -- it ends with:
td[1]/td
you could try to check out what the text value is directly in IE by appending /text() to the xpath expression. Maybe it finds the empty string?
String servicenameidtext = "//table[#id='release_hostsProcesses_list']/tbody/tr[2]/td[1]/td/text()";
alert("found:" + servicenameidtext);
My two cents,
Try to use all lowercase characters in id field:
String servicenameidtext = "//table[#id='release_hostsprocesses_list']/tbody/tr[2]/td[1]/td";
Selenium.getText(servicenameidtext );
Should work in both FF and IE
In this Case we can do 1 thing
To Inspect Elements for Internet Explorer IE Developer Tools is available and for FireFox Firebug
We can compare both Inspections Derive the XPath/CSS from IE Developer Tools for the Object.
Use and Check is it working in both IE and FF
If it works Fine Otherwise Conditionally we can use the corresponding XPath According to Browsers.