0

When we use selenium command at that time command not find and attribute not get? See below command.

<table>
  <tr><td>open</td><td>http://www.wikipedia.org/</td><td></td></tr>
  <tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
  <tr><td>assertAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
  <tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>language</td></tr>
  <tr><td>verifyAttribute</td><td>xpath=//div[2]@class central-featured</td><td>central-featured</td></tr>
  <tr><td>verifyAttribute</td><td>xpath=//div[2]@class central-featured</td><td>search1</td></tr>
  <tr><td>assertAttribute</td><td>xpath=//div[2]@class central-featured</td><td>central-featured</td></tr>
</table>

I am using Selenium IDE 2.5.0 in Mozilla Firefox and Ubuntu.

2
  • Can you show the HTML you're testing this against? Commented Feb 15, 2014 at 12:20
  • @t0mppa when we save this command or we write in text in table format then we can see HTML and we can also change it and reflect to direct in IDE Commented Feb 15, 2014 at 12:41

4 Answers 4

1

Xpath //div[2]@class central-featured is invalid. Try changing it to //div[@class='central-featured']/@class if you mean to select a class. You could also use assertElementPresent function instead of selecting attribute, if the whole point is to check that element exists, i.e.: <tr><td>assertElementPresent</td><td>xpath=//div[@class='central-featured']</td><td></td></tr> Much simpler that way.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Use xPaths in this case.
  2. Use google chrome's built in developer tool for this
  3. Place your cursor on the element
  4. Press Ctrl+Shift+C
  5. Click the Element
  6. That clicked Element's code is highlighted in the short window on the bottom
  7. Right-Click on highlighted code
  8. Select Copy > Copy XPath

Here it is you have copied the xPath for that specific element. This is shown in the image:

Click to see how to copy xPath

Comments

0

The Xpath you have used in Invalid.

You can use xpath as follows and through this you can fins xpath of any object - just need to study the concept:

Google

Here as we can see we want to search Google Search just by writing its xpath in console So to find the Google Search button we have to write xpath like this

//span[@id='gbqfsa']

Once we hit enter it would bring

[ gbqfsa">​Google Search​​ ],

It shows that xpath for Google Search Button is correctly written

Now suppose we want to search Google Search button if we are just familiar that id attributes start with gbqfs

then we have to use function starts-with like this

//span[starts-with(@id,'gbqfs')]

and once when we hit enter on console it would reflect two button one is Google Searchand Second one is I’m Feeling Lucky

[
gbqfsa">​Google Search​​
,
​I'm Feeling Lucky​​
]

So to find out the Google Search uniquely we need to complete id attribute to gbqfsa

“//span[starts-with(@id,'gbqfsa')]

and hit to enter and now it would reflect only

[
​Google Search​​
],

It proves that we have written right xpath for Google Search

In the same fashion we can use Contains function to find the Google Search button like this here I have taken fsa from gbqfsa //span[contains(@id,'fsa')]

hit enter and hopefully it will return

[
​Google Search​​
],

if there are multiple attributes then we can use: //span[contains(@id,'fsa') and contains(@class, 'xyz')] hit enter and hopefully it will return

Information Source: Sumit Mittal Blog

1 Comment

Your Welcome Tehsil - can you vote my answer or select as appropriate.
0

You can use CssSelector as below

webDriver.findElements(By.cssSelector("div.central-featured")) // for more than 1 elements with same class

webDriver.findElement(By.cssSelector("div.central-featured")) // for 1 element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.