Solving Unable to locate element error in HTML5

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: new Actions(driver).moveToElement( driver.findElement(By.className(“m-textarear”))).sendKeys(“Selenium Wiki”).perform();

How to locate an element by Xpath with its dynamic title

Example: I have two images ImageHTMLCode 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 the solution: If you want to click on the first try this : //IMG[contains(@title,’Critical since’)][1]

Using Xpath when you have new line text

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. User-agent: * Disallow: /clickthrough.html Disallow: /details.html Disallow: /post-sendtofriend.html Use normalize-space(), which will throw away the leading and trailing whitespace characters (and condense repeating spaces in the middle of the text […]

Using regular expression in Selenium

Here is the xpath I want to use regular expression. Code with out using regular expression: Assert.IsTrue(selenium.IsElementPresent(“ctl00_5hh5_g5656_675gffg042f_tbSearch”)); Code using regular expression: Assert.assertTrue(selenium.isElementPresent(“css=input[id$=’tbSearch’]”)); Alternative is to use contains in the xpath. Here is the example: //input[contains(@id,’tbSearch’)]

Using regular expressions in xpath Selenium

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. Here is my HTML source code: Abrasion Resistance Access Panels Access Solutions Accessories Acoustic Performance Affordable Playground Equipment Aged […]

Handling Selenium error – verifyXpathCount

Here is an error that I got when I executed the following verifyXpathCount command <tr> <td>verifyXpathCount</td> <td>xpath=//span[@id=’ctl00_contentSection_GoogleAFSRight’]/div/div[@class=’SingleVertical’]/a[@class=’Heading’ and @href]</td> <td>4</td> </tr> Error Message Unexpected Exception: message -> The expression cannot be converted to return the specified type., code -> 52, INVALID_EXPRESSION_ERR -> 51, TYPE_ERR -> 52, result -> 2153447476, name -> NS_ERROR_DOM_TYPE_ERR, filename -> chrome://selenium-ide/content/selenium/scripts/htmlutils.js, […]

Selenium – verifyXpathCount

verifyXpathCount(xpath, pattern) Generated from getXpathCount(xpath) Arguments: * xpath – the xpath expression to evaluate. do NOT wrap this expression in a ‘count()’ function; we will do that for you. Returns: the number of nodes that match the specified xpath Returns the number of nodes that match the specified xpath, eg. “//table” would give the number […]

Using Xpath in Selenium and Selenim RC

The HTML Example Document [html] <div> <ol> <li> <a title=”Self Catering Apartments” href=””>Self Catering Apartments</a> </li> <li> <a title=”Vacation Accommodation” href=””>Vacation Accommodation</a> </li> <li> <a title=”Hotel” href=””>Hotel</a> </li> <li> <a title=”Real Estate” href=””>Real Estate</a> </li> </ol> </div> [/html] Uisng xpath to verify all the a tag elements xpath = //div/ol/*/a[@href] This will return all the […]