TestCafe: problem with specifying selector: span to grab text - testing

I would like to grab the text from span but I have a problem with pointing this selector.
I tried defined it following:
this.channelName = Selector('span[class="scheduler-header__service-name"]');
or
this.channelName = Selector('div').find('#schedule').find('.scheduler-header').find('.scheduler-header__service-name')
And I always received information:
“Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.”
Could somebody declare this selector for me?

it was easy:)
this.channelName = Selector('.scheduler-header__service-name');

Related

Testcafe - How to write testcafe selector to identify element with class contains

I need to write the location of an element in page which has just the tag name and only 1 attribute - class and the class value has number characters which is dynamic so I have to use contains to specify the element.
Could not traverse from parent node as it is a list with similar parent name.
Any Suggestions please??
You can use the Selector.withAttribute method.
For example, the following code finds an input with an attribute, which name ends with 'testId' and clicks on it.
await t.click(Selector('input').withAttribute(/.*testid/);

Unable to find element when uploading file in TestCafe

enter image description here
I wrote code below
let browseButton = await Selector('input').withAttribute('id', 'card_image_1583116662160_11.707407693474106');
await t
.click(Selector('.fa.fa-image'))
// upload img
.setFilesToUpload(browseButton,'../../artifacts/uploads/boba.jpg')
but the result is
1) The specified selector does not match any element in the DOM tree.
| Selector('input')
> | .withAttribute('id', 'card_image_1583116662160_11.707407693474106')
It looks like you are trying to use a dynamic ID in your Selector. In this case you should create your Selector based on CSS classes or other non-dynamic attributes. Please refer to this documentation section: https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/.
The following example may be also useful: https://github.com/DevExpress/testcafe-examples/blob/master/examples/element-properties/check-element-markup.js. The example shows how to access DOM properties and verify them with assertions (you can "debug" each level of the Selector hierarchy).
Please let me know if anything remains unclear.
UPDATE: Select Elements With Dynamic IDs
UPDATE 2: RegExp example - Selector('input').withAttribute('id', /card_image_\w+/)

i am not able find dynamic element in android app

i have dynamic elements in my android app and there is nothing to find it out .Please check screen shot of my app and attributes and let me how can we do it.
I have tried with the given attributes
I just want ti find these elements and send keys
Try find element by xpath with this value:
//*[contains(#class,'android.widget.EditText')]
It will return the first element if there are many elements with same class.
If you want other element with class EditText, you can add count like this:
(//*[contains(#class,'android.widget.EditText')])[2]
The above for second element.
I tried this way of finding element:
List name = driver.findElements(By.xpath("android.widget.EditText"));
name.get(0).click();
But i am getting bellow error:-
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Please let me know what is the issue?
I found one of my dynamic element through this method :-
findElementByXPath("//android.widget.FrameLayout[#index='0']/android.widget.EditText[#index='0']")
but for second element also , these details are same, so if i am putting same method to find second element , it search the first one only.
Than i printed size of the element with this find method
Size is coming like this
(996, 89)
Please let me know how can i find second element , because it has same details.

Unable to locate list elements using Nightwatch

I have some list elements:
< button id={"productBook"} className="fito-btn fito-btn-long" style={this.props.styles.btnBrandRevers} onClick={this.props.onOfferSelect.bind(null, product)}>
< FormattedMessage id='app.Book' defaultMessage='Book' />
< /button>
When asserting the element with id productBook as:
.assert.visible('button[id=productBook]')
I'm getting an error:
Testing if element <button[id=productBook]> is visible. Element could not be located. - expected "true" but got: "null"
I don't understand why this doesn't work for this specific element while it works for other elements. Is there some different way that list elements need to be verified?
Please help.
Try using the shorthand # for id:
assert.visible('button#productBook')
or
assert.visible('#productBook')
As per the HTML you have shared the id attribute of the <button> is dynamically generated. So you may not be able to assert through id. Instead you can assert the visibility of the FormattedMessage through the following Locator Strategy :
xpath :
//button[#class='fito-btn fito-btn-long']/FormattedMessage[#id=\"app.Book\"][#defaultMessage='Book']
Try the following:
.assert.not.elementPresent('tr[...]')

Get Sibling using Xpath

I'm trying to verify is a checkbox is checked or not and trying to build a robust xpath. I need to figure out how to transverse from 'Password Never Expires' text to img scr with attribute title?
You first need to select the td that has the text 'Password Never Expires', this is quite straightforward:
//td[text()='Password Never Expires']
When you have this element you can use the Axis [following-sibling][1] to get the following td node:
following-sibling::td
Now you have the node that contains the img node, all you have to do now is to get the #src attribute of this node:
img[#title='Checked']/#src
Putting all the above together will give you:
//td[text()='Password Never Expires']/following-sibling::td/img[#title='Checked']/#src
Hope this helps.
You can use this Xpath :
//td[contains(#class,'Never Expires')]/parent::td//following-sibling::td[#class='dataCol']/img
try out ! and let me know if it works for you or not.