I am currently working on a HTML5 project and I encountered an error “Unable to locate element:”. I tried using xpath, className and even cssSelector. I was getting the same error.
I then used advanced webdriver org.openqa.selenium.interactions; Class Actions and that solved the problem.
Here is the code:
Example: I have two images
some_date1 and some_date2 are generated dynamically.
How to locate them using CSS locator ?
click css=img[title*='since'] : will not work because it won’t
make difference between the two images.
Here is an example where there are new lines and have to validate if the exact text is displayed in the correct order using xpath.
Use normalize-space(), which will throw away the leading and trailing whitespace characters (and condense repeating spaces in the middle of the text into a single space), so that you can compare the normalized text() and use to filter in a predicate.
Here is the xpath code to validate the above text
selenium.getText("//test[normalize-space()]").Equals("pass the string here");
Here is the xpath I want to use regular expression.
Code with out using regular expression:
Code using regular expression:
Here is an example where I have used regular expressions in xpath.
This article includes a code sample that demonstrates how you can use the starts-with XML Path Language (XPath) string function to implement this requirement.
You can use selenium.IsElementPresent(“element”) to see if a particular element is present on the web page. This is a very powerful function in selenium as you can use it with a if condition.
In this example I am first checking if there is an element //td[@class='Selenium'] on the web page. If yes then I click the element //td[@class='Selenium'] and continue checking the other conditions.