2

I have tried to handle the dynamic xpath and css selector by many ways, but not getting the correct solution. Please help me out regarding this issue.

xpath is //*[@id="product_properties_attributes_15434094021_value"]

Here the number "15434094021" is changing every time at the time of opening the page. I have also tried with css selector by it is not solved. I have tried with "Starts with" & "Contains", but not solved. Before the same type of questions are posted and answered also. But this question is not solved and that is why I have posted this question.

getting this error for starts-with

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*div[starts-with(@id,'product_properties_attributes_')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*div[starts-with(@id,'product_properties_attributes_')]' is not a valid XPath expression.

And this below-mentioned error for using "contains" -

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*div[contains(@id,'product_properties_attributes_') and contains(@id,'_value')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*div[contains(@id,'product_properties_attributes_') and contains(@id,'_value')]' is not a valid XPath expression.

Kamal
  • 2,384
  • 1
  • 13
  • 25
  • Can you share the url? – Kamal Dec 03 '18 at 07:29
  • Could you please tell me which URL I need to share? – Pinaki Mohon Bag Dec 03 '18 at 07:45
  • The url where you are trying to work with these elements of dynamic xpath – Kamal Dec 03 '18 at 07:49
  • As uid and pw required to open the link - it cannot be shared. I have given the xpath. – Pinaki Mohon Bag Dec 03 '18 at 10:16
  • @kamal - probably this can help you to find out... – Pinaki Mohon Bag Dec 03 '18 at 12:42
  • I can see two issues from your traces, 1. Quoting issues(reason for syntaxerror): You have to use double quotes for strings inside single quotes and vice versa. 2. The element you shared in last comment is an `input` element, but according to traces, you are looking for `div` element. – Kamal Dec 04 '18 at 01:12
  • Now, I am giving this - productSKU = driver.find_element_by_id("[contains(@id,'product_properties_attributes_')]") but it is showing that "Unable to locate element". – Pinaki Mohon Bag Dec 04 '18 at 06:01
  • I don't think use of `contains` like this with `find_element_by_id` works. You can try `find_element_by_xpath("//*input[contains(@id, 'product_properties_attributes_')]")` – Kamal Dec 04 '18 at 06:23
  • @kamal , Now I am getting this error - selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*input[contains(@id, 'product_properties_attributes_')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*input[contains(@id, 'product_properties_attributes_')]' is not a valid XPath expression. – Pinaki Mohon Bag Dec 10 '18 at 10:40
  • Please try this: `find_element_by_xpath("//input[contains(@id, 'product_properties_attributes_')]")` I had added the * by mistake – Kamal Dec 11 '18 at 03:51
  • Getting this error - selenium.common.exceptions.ElementNotVisibleException: Message: element not visible – Pinaki Mohon Bag Dec 11 '18 at 05:24
  • It is hard to help you without the full html, one suggestion: please check if this element is inside `iframe` tag – Kamal Dec 11 '18 at 05:44
  • This is the html for that field - - the big number is changing all the time... – Pinaki Mohon Bag Dec 11 '18 at 06:41
  • You are seeing a `InvalidSelectorException` unless you update the question with relevant HTML this question can't be answered. – undetected Selenium Dec 11 '18 at 11:21
  • This is the required HTML file ...please check...
    – Pinaki Mohon Bag Dec 12 '18 at 08:08
  • Found any way to solve this? – Pinaki Mohon Bag Dec 17 '18 at 06:15

0 Answers0