Is it way to wait some text via attribute - karate

I would like to wait some text in the following format:
waitUntil(locator, attribute, attributeValue)
Examples from tutorial page do not meet the necessary conditions:
And waitUntil('#eg01WaitId', "_.innerHTML == 'APPEARED!'")
And waitForText('#eg01WaitId', 'APPEARED')

Take some time to read and understand the documentation. What you are looking for is this:
* waitUntil('.some-class', "_.getAttribute('some-attribute') == 'some-value'")

Related

Karate UI: Entering input using variable values

KarateUI question
I'm trying to enter values in a text field using a variable. Example:
* def foo = bar
* waitFor("input[aria-label='Search Input']").input('<foo>' + Key.ENTER)
This results in value being entered in the Search Input field.
I have been using the '<[something]>' successfully on a number of other places, not sure why it's not working in the above example.
I have tried a number of other approaches following the documentation without much luck.
Karate "variables" can be mixed into plain JavaScript. So try this:
* def foo = 'bar'
* waitFor("input[aria-label='Search Input']").input(foo + Key.ENTER)
That's right, no angle-brackets required.
Also see: https://github.com/karatelabs/karate#scenario-outline-enhancements
If still stuck, follow this process please: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

How to locate an element by both class name and accessibility ID?

I am automating a windows application through a desktop session using Appium and Windows Application Driver. Certain elements I want to interact with don't have unique accessibility IDs but the combination of their class names and IDs does seem to be unique.
How can I first get a list of elements by their class name and then fetch one of them with certain ID?
I am aware that the second line of code provided is not correct, I'm just showing it to demonstrate what behavior I need.
Below is through class name:
class_elements = driver.find_elements_by_class_name("some_class_name")
Below is through an accessibility id:
specific_element = class_elements.find_element_by_accessibility_id("some_id")
specific_element.click()
Is there a way to put both of these together in a loop?
Thank you #Moshe Slavin for your suggestion
I tried the following piece of code
#pytest.mark.trial
def test_trial():
className = "UIProperty"
class_elements = ds.find_elements_by_class_name("UIProperty")
for elm in class_elements:
print(elm.get_attribute('id'))
if elm.get_attribute('id') == "System.ItemNameDisplay":
elm.click()
I decided to print the IDs as well. I got the following results:
None
None
None
...
I'm quite confused as to why this is happening. I'm using the Windows Inspect tool from SDK to gather properties of the UI elements and there definitely is and element present that matches both the class name and the ID.
It should look something like:
class_elements = driver.find_elements_by_class_name("some_class_name")
for elm in class_elements:
if elm.get_attribute('accesibilityID') == "some_id":
elm.click()
EDIT:
As #Bill Hileman has pointed out the attribute OP was looking for is accesibilityID not just id.
Thanks Bill
Hope this helps you!
Moshe Slavin answer works, but you can try like this also.
Suppose you have some class name and you are storing it in some variable like below :
className = "some class name"
then you can get all the matching class names using the below line and you are aware of that :
driver.find_elements_by_class_name(className)
Instead of finding all the elements and storing the values, store the accessibility id that you want to check in some variable like below :
accessibilityID = "some accessibility id"
Then you can search for an element which contains both the class name and accessibility id(is just for an indicative purpose, so use app related attribute which identifies required field) using the below xpath without performing any looping :
element = driver.find_element_by_xpath("//*[#class='"+className+"' and #accesibilityID='"+accessibilityID +"']");
I hope it works too...

Getting description using selenium xpath

I am trying to get the job description for job search page indeed.com This is how it looks like
Provide technical leadership around
QA
automation to IT teams. Work with various team to promote
QA
processes, practices and standardization....
Any idea how can I get that description? I tried the following:
//span[contains(#class,'summary')]
That does not give me the text description. Should I xpath or is there any other solution? Thanks in advance for your time.
This XPath are correct.
//span[contains(#class,'summary')]
//span[#class='summary']
I'm a Python guy, But I translated it to Java. You can do:
element = driver.findElement(By.name("summary"));
element = driver.findElement(By.className("summary"));
element = driver.findElement(By.cssSelector('span[class="summary"]');
And remember that If you want the element text, every element has the method .getText(), the find* functions only retrieve the element/s.
Double check you were not using driver.findElements(By.xpath()) in plural. In that case you should first retrieve the individual elements. Then access to the .getText() method.
description = driver.findElement(By.className("summary")).getText();
System.out.print(description);
Alternatively you could do:
description = driver.findElement(By.className("summary"));
description_text = description.getAttribute("innerHTML");
System.out.print(description_text);
If your problem is that your element is not visible or reachable (stale). Then you can use javascript.
element = driver.executeScript("return document.querySelector('span[class=\"summary\"]');");
For more reference:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html

Finding text on page with Selenium 2

How can I check whether a given text string is present on the current page using Selenium?
The code is this:
def elem = driver.findElement(By.xpath("//*[contains(.,'search_text')]"));
if (elem == null) println("The text is not found on the page!");
If your searching the whole page for some text , then providing an xpath or selector to find an element is not necessary. The following code might help..
Assert.assertEquals(driver.getPageSource().contains("text_to_search"), true);
For some reason, certain elements don't seem to respond to the "generic" search listed in the other answer. At least not in Selenium2library under Robot Framework which is where I needed this incantation to find the particular element:
xpath=//script[contains(#src, 'super-sekret-url.example.com')]
A simpler (but probably less efficient) alternative to XPaths is to just get all the visible text in the page body like so:
def pageText = browser.findElement(By.tagName("body")).getText();
Then if you're using JUnit or something, you can use an assertion to check that the string you are searching for is contained in it.
assertThat("Text not found on page", pageText, containsString(searchText));
Using an XPath is perhaps more efficient, but this way is simpler to understand for those unfamiliar with it. Also, an AssertionError generated by assertThat will include the text that does exist on the page, which may be desirable for debugging as anybody looking at the logs can clearly see what text is on the page if what we are looking for isn't.

selenium getXpathCount

HI there
selenium.getXpathCount does not find element, any one hoas any idea ? Here is my code:
if (existArtist){
int result = selenium.getXpathCount("//*[#id='chugger-results']/div[1]/ul/li").intValue();
if (result>0){
//DO THIS
Either you have a broken DOM (Do a W3C Validation and see if you have any unclosed tags) or your XPath is looking for an element that doesn't exist.
We would need to see the entire HTML of the page to be able to answer your question (more visibility of your test code would be useful too)