Using XPATH to extract input value from google maps inputbox [duplicate] - selenium

I am trying to extract the text in an input box,
<input type="text" name="inputbox" value="name" class="box">
I started with
input = driver.find_element_by_name("inputbox")
I tried input.getText() but I got
AttributeError: 'WebElement' object has no attribute 'getText'

Use this to get the value of the input element:
input.get_attribute('value')

Note that there's an important difference between the value attribute and the value property.
The simplified explanation is that the value attribute is what's found in the HTML tag and the value property is what you see on the page.
Basically, the value attribute sets the element's initial value, while the value property contains the current value.
You can read more about that here and see an example of the difference here.
If you want the value attribute, then you should use get_attribute:
input.get_attribute('value')
If you want the value property, then you should use get_property
input.get_property("value")
Though, according to the docs, get_attribute actually returns the property rather than the attribute, unless the property doesn't exist. get_property will always return the property.

Related

In Angular, does `name` in `<input [value]="name">` mean string literal or a property?

In the following code
<input [value]="name">
Is name a string literal or a property? I understand the code inside the double quotes is an expression. So I suppose name should be a property defined in my component class. If that is the case, is is possible to assign a string literal to value i.e. [value]="name" where name is not a property of an object but a literal? Would I have to remove the [] so that name gets assigned to the value attribute of input and not value property?
The use of the square brackets is called a binding, so taking the two examples from the comments:
<input [value]="name">
This would bind the variable name to the value of the input element. If you update the name variable in your code the input value shown will change. Note this is one-way binding, meaning that if you change the input text, your name variable will not update with the new value. For that use case you'd use [(value)]="name"
<input [value]="'name'">
This would bind the string literal 'name' to the value of the input element, so the input would should the literal text name

Why is variable substitution only recommended for values that wont change during lifetime of a widget?

Regarding Variable Substitution in Dojo
Variable Substitution:
A template can have values set on DOM rendering
though the use of a simple variable placeholder syntax, which looks
like this:
${property}
According to the documentation
Variable substitution in a template is only recommended for values
that will not be changed during the lifetime of the widget. In other
words, if you expect to be able to set the value of a property in a
widget during the lifetime of your application programmatically, we
recommend instead using your widget's postCreate method to set any
variables programmatically through your widget's set() method.
Can someone explain why this recommendation is made?
Variable substitution in Dojo has no binding.
This mean it wont change even if you change the actual value of the variable.
If a binding is needed, then you can use an attach point and a setter for that value. It will then have a binding and the UI will be updated with the new value.
Something like this:
_setLabelAttr : {
node : "_tplLabelNode",
type : "innerHTML"
},
Will bind the innerHTML of attach point _tplLabelNode to the "label" property of the widget.
So widget.set('label', 'foo'); will update the UI.
However <div>${label}</div> has no bind. ${label} will be replaced at creation of the widget and will never be updated

Geb: text() vs value()

Just a small clarification on using Geb text() vs value().
According to the Geb documentation:
The value text is treated specially as a match against the node’s text.
And for value():
Calling value() with no arguments will return the String value of the first element in the Navigator.
From my understanding through trial-and-error, text() can be used to check/set the text content in a particular element, EXCEPT form elements. value() is used to check/set the content of a form element.
assertThat($("h1").text()).isEqualTo("Geb") // will work
assertThat($("input").value()).isEqualTo("Geb") // will work
assertThat($("input").text()).isEqualTo("Geb") // will not work
Is this correct? Or is there a greater differentiation? I couldn't find any substantial description in the documentation.
Thanks in advance!
You cannot use text() to set anything, it only returns the first element's text content. It basically delegates to WebElement.getText().
The text you quoted:
The value text is treated specially as a match against the node’s text.
Relates to using an attribute selector like `$("div", text: "Lorem ipsum...").
And yes, value() and value(Object) can be use to retrieve and set value/text of an input.

Core Data - Fetch object with optional attribute

I have an EntityA which has an optional attribute int32 result. When I create EntityA I do not set the result attribute. Then later on when I fetch it I expect it to have nil value but for some reason it's set to 3 even though I have not set this attribute.
What's going on here?
1st possible issue:
You have set a default value in the model editor. Select the attribute and check the inspector.
2nd possible issue:
You are retrieving or showing the wrong value. Show the code you are using to find out that result is '3'.
3rd possible issue:
You are setting the value later inadvertently, perhaps in a loop or something similar. Do a text search for the attribute to find a possible occurrence in your code.
Your int32 will be stored wrapped into a NSNumber object. If you don't provide a value, no NSNumber object will be created - sql will treat it as NULL.
The iOS Core Data Programming Guide says:
You can specify that an attribute is optional—that is, it is not
required to have a value. In general, however, you are discouraged
from doing so—especially for numeric values (typically you can get
better results using a mandatory attribute with a default value—in the
model—of 0). The reason for this is that SQL has special comparison
behavior for NULL that is unlike Objective-C's nil. NULL in a database
is not the same as 0, and searches for 0 will not match columns with
NULL.
So, it may be better to either make the attribute mandatory and set it to a distinct value, or to pass in NSNumber from the start.

What does dijit.registry.remove() do?

What does dijit.registry.remove() do? How does it handle invalid parameters?
The dijit.registry reference is an instance of dijit.WidgetSet, which is a collection of widgets.
The remove() function accepts an input ID and removes that Widget with the corresponding ID from the collection, if found.
In Dojo 1.4, WidgetSet is defined within dijit/_base/manager.js.
The passed ID is used internally as the key looked in an associative array. It's used like: this._hash[id], so passing it garbage will result in nothing being found or removed.