I am trying to assign a value to and output field based on an input field inside the modified Javascript step. I have coded as:
if ( !(person_id.isNull()) )
person_nm = substr(another_field,1,10)
else
person_nm = "";
When I run this I get the error:-
Modified Java Script Value.0 - Javascript error:
Modified Java Script Value.0 - TypeError: Cannot find function isNull in object 7853. (script#90)
So where am I going wrong?
In the else part I am actually supposed to assign a NULL to person_nm but I can't find a way to do so. Whats the way this can be achieved?
Thanks,
Kanishk
In modified java script you can use below condition.
If (abc === null)
{
}
IsNull() is not a vanilla Javascript function. It’s available in a number of frameworks, e.g. jQuery, but not in plain JS.
In plain JS, you can do:
if(!person_id)
person_nm = substr(another_field,1,10)
else
person_nm = "";
Related
I have a C# selenium/Appium project where I need to find a desktop Application window By.Xpath("").
This works:
By.XPath("//*[#Name='ASDASD']");
However, some builds of the app have the window name be "ASDasd", which causes the Xpath above to not find the window element and the test fails.
Is it possible to Ignore the case of the #Name attribute whether it be "ASDASD", "ASDasd" or something else?
I did try using the XPath translate function, but I am not able to find the element, I assume I am doing it wrong.
What I tried:
By.XPath("//*[translate(name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'asdasd']")
or
By.XPath("//*[translate(name(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'asdasd']")
or
By.XPath("//*[#Name='translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'asdasd'']")
or
By.XPath("//*[#Name='translate(asdasd,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')']")
Maybe some other variations too, but I could not get it to work.
Some of the examples may have invalid formatting.
While other seems to be valid but could not find the element and it would timeout.
UPDATE:
Thank you for the assistance, this worked:
By.XPath("//*[translate(#Name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='asdasd']");
However, it added 60 seconds to the test somehow, it seems to stall for 60 seconds on one of the places where it looks for the main window.
Thanks for the help!
Regards
name() gives you the name of context node. In this case (//*), the name of whatever element you are currently looking at. You meant to write #Name, i.e. the attribute that happens to be called Name.
By.XPath("//*[translate(#Name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'asdasd']")
Using translate() is clunky and fails when the search string contains unanticipated characters.
Unfortunately, there is no lower-case() function in XPath 1.0. But you can work around this limitation with the help of the host language (such as C#).
The following will dynamically create an XPath expression which finds arbitrary values case-insensitively:
var searchValue = "asdasd";
var uc = searchValue.ToUpperInvariant();
var lc = searchValue.ToLowerInvariant();
var xpath = $"//*[translate(#Name, '{uc}', '{lc}') = '{lc}']";
// -> "//*[translate(#Name, 'ASDASD', 'asdasd') = 'asdasd']"
I have successfully implemented react-native-cn-richtext-editor with limited toolbar functions.
I want to know that, how to get value (text that we have typed) from editor.
I am new in RN, have tried to get value but didn't get success. How can I resolve this issue, as I want to sent this text to server and then do further process.
In given example of this library there is method onValueChange on change the content object is present in value and to extract the value below example is there
onValueChanged = (value) => {
console.log(value[0].content[0].text)
}
Finally I got the solution of above question.
convert the value in HTML with convertToHtmlString write following command,
let html = convertToHtmlString(this.state.value)
for more details refer this github link
This line of code:
$this->fillField('xpath','//fieldset[#id="address-container"]/input[#name="address_add[0][city]"]', "Toronto");
Is giving me this error
Form field with id|name|label|value|placeholder "xpath" not found. (Behat\Mink\Exception\ElementNotFoundException)
The reason I want to use xpath in my fillField is because there are actually multiple input[#name="address_add[0][city]"] in my html document. I figure an xpath will let me target specifically the field I want to populate.
What's the best way to fill out just the input[#name="address_add[0][city]"] that is a descendant of fieldset[#id="address-container"] ?
You are not using the method in the wright way.
As i see here xpath is taken as selector.
The method expects 2 parameters:
identifier - value of one of attributes 'id|name|label|value'
value - the string you need to set as value
If you want to use css|xpath then you need to use find method first.
For example:
$this->find('xpath', 'your_selector')->setValue('your_string');
Please note that find might return null and using setValue will result in a fatal exception.
You should have something like this:
$field = find('xpath', 'your_selector');
if ($field === null) {
// throw exception
}
$field->setValue('your_string');
Also your selector could be written as:
#address-container input[name*=city] - this with css
or
//fieldset[#id="address-container"]//input[contains(#name, 'city')] - this with xpath
Make sure you take advantage of your IDE editor when you have any doubts using a method and you should find a php doc with what parameters are expected and what the method will return.
If you are using css/xpath a lot you could override find method to detect automatically the type of selector and to use it like $this->find($selector);
Also you could define another method to wait for the element and to handle the exception in one place, for example waitForElement($selector) that could contain a conditional wait up to 10 seconds and that throws exception if not found.
I'm attempting to implement SlickUpload in VBHTML.
Using the C# Razor example I am getting a expression expected error.
.SelectorTemplate =
new Template(#<text> Add files</text>)
I think this is something to do with #, but I'm not sure. Is it possible to use the text syntax in vbhtml?
Just my initial guess without seeing the full code block, but the parameter to the constructor of Template should be in double-quotes.
.SelectorTemplate =
new Template("<text> Add files</text>")
Turns out you need to add a lambda expression to the new template
.SelectorTemplate =
New Template(Sub() #<text> Add files</text> End Sub)
I have a form text field that is being populated with a default value. I would like to clear the value and enter white space to assert that the expected validation occurs. I am using Selenium RC and the PHPUnit Selenium extension. How can I achieve this?
Note: I have already tried doing these, but they do not work:
$this->type('FirstName', " "); //spaces
$this->type('FirstName', "\t"); //tab character
They clear the value from the field, but they do not enter the white space into the field.
Update: I found that if you are using Selenium IDE, you can type white space by using their ${space} variable but this does not work when using Selenium RC and the PHPUnit Selenium extension.
recently I am having the same problem just like Andrew where the ${space} isn't work in Selenium RC. I found out that Zugwalt's solution is useful. Here is what I did to capture the whitespace.
selenium.focus("txt_textbox1");
selenium.keyPressNative("32");
strOutput = selenium.getEval("this.browserbot.findElement('txt_textbox1').value = ' ';");
Hope this help ;)
THanks #!
I fixed this in the phpunit-selenium code on github and made a pull request to the maintainer.
Here is my gist if anyone cares:
https://github.com/undernewmanagement/phpunit-selenium/commit/1b783ba8cfe4736f525b316a75a991e0a701afd1
You could use javascript injection and manipulate the value directly
selenium.getEval("this.browserbot.findElement('FirstName').value = ' ';");
Note this will not fire off any events so you would have to manually trigger them if desired.
How about setting it's value to an empty string ('')?
How about using the keyPress() function to "press" the spacebar?
You can try selenium.typeKeys('FirstName'," ");
Please let me know if it worked.
This should work for phpunit with Selenium:
class MyTest extends PHPUnit_Extensions_Selenium2TestCase
{
public function testSomething()
{
$textField = $this->byCssSelector('.blah');
// ...
$textField->clear();
$textField->value(" ");
// test assertion to follow
}
}
If you want to enter a sentence, the following won't work:
$textField->value("this is a sentence.");
The following will:
$textField->value("this");
$textField->value(" ");
$textField->value("is");
$textField->value(" ");
$textField->value("a");
$textField->value(" ");
$textField->value("sentence.");