Unable to find xpath

Unable to find the element located by 'By.xpath: id(“product_attribute_2”)[count(. | //select[@name = ‘product_attribute_2’ and @id = ‘product_attribute_2’ and (text() = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
’ or . = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
')]) = count(//select[@name = ‘product_attribute_2’ and @id = ‘product_attribute_2’ and (text() = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
’ or . = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
‘)])]’. Please recheck the objects properties to make sure the desired element is located.

Just test and play around with the xpath in chrome console using $x("")…
PS. Selecting stuff by html ID and more… the ‘more’ shouldn’t matter since the ID should be unique…

hi,

try to use css selector as locator

yes , i try with it but it display this type of error:-
"Unable to find the element located by 'By.cssSelector: '. Please recheck the objects properties to make sure the desired element is located. "

'By.xpath: id(“product_attribute_2”)[count(. | //select[@name = ‘product_attribute_2’ and @id = ‘product_attribute_2’ and (text() = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
’ or . = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
')]) = count(//select[@name = ‘product_attribute_2’ and @id = ‘product_attribute_2’ and (text() = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
’ or . = ’
2 GB
4GB [+$20.00]
8GB [+$60.00]
‘)])]’.

How did you create this terrible expression? Did you write it yourself manually? I believe not. I suppose you got it using Spy or Recorder tool. I am not hopeful that this expression works.

You should not rely on these tools without learning XPath and CSS Selectors. You should study XPath or CSS Selector from books or tutorials (e.g, https://www.guru99.com/xpath-selenium.html) first. You should try to learn so that you can write appropriate expressions manually. Once you got basic understanding about XPath and CSS, then the Recorder & Spy tools will help you by generating boilerplate codes. You are supposed to manually modify the generated codes a lot to make them correct and useful.

this is not write by myself.this is by default code. now it is working.thank you for your support.and please can you give me some better and easy tutorials of xpath and css for learning so i can increase my knowledge.

This is a good web page to learn xpaths: XPath in Selenium: How to Find & Write Text, Contains, OR, AND . You have to choose a web page and right click on any element o the page, go to the html section and press : ctrl + f keys and you can generate or evaluate any xpath

hello,

still i’ll suggest to use css selector instead of xpath

yes , i try with it but it display this type of error:-
"Unable to find the element located by 'By.cssSelector: '. Please recheck the objects properties to make sure the desired element is located. "

Thank you for your support and time.i will learn from this site.:slight_smile: