0

For the moment, I'm looking to make a program for a repetitive action which we need to make something like 1000 times by hand otherwise.

This action is done throughout a web browser (I'm using Chrome). My actual issue is the XPATH selector is changing at every connection but only one number. So, I use the recognition on the webpage linked using Selenium and associated WebDrivers.

The fact is my code run sometimes when the selector has the right name.

Indeed, as the css selector is changing permanently, it happens that this is the right one !

So, after making a headless browser, login to the company webpage, I have to recognize then click on a specific object on the navigator :

The problematic code is the following:

wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="__xmlview0--settingsButton-img"]')))
OT = driver.find_element_by_xpath('//*[@id="__xmlview0--settingsButton-img"]')
OT.click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#__select1-label')))
driver.save_screenshot("screenshot.png")

I have an idea but I don't know how to do it: Is it possible to add a random number instead of the 0 in xmlview0, which is the number issue within the CSS selector ?

I'm not a Python veteran and I really don't want to do the job by hand.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Apr 27 '18 at 12:11
  • Compressed, I think you are asking whether it is possible to select an HTML element by `id` with a string containing a wildcard. Is that an accurate summary? – halfer Apr 27 '18 at 12:13
  • Yes, it is an accurate summary. Sorry, it's the first time I use tool like help forum ;-) – ARn Lamourette Apr 27 '18 at 13:12
  • You could use two [XPath `contains()`](https://stackoverflow.com/questions/1064968/how-to-use-xpath-contains-here#1065237) operators: one `__xmlview` and the other `--settingsButton-img`. – halfer Apr 27 '18 at 13:16
  • Possible duplicate of [XPath: using regex in contains function](https://stackoverflow.com/questions/21405267/xpath-using-regex-in-contains-function) – halfer Apr 27 '18 at 13:18
  • ^ I think the question is an exact duplicate of that one. Do either of these help? It seems this is an XPath question and not really about Python at all. – halfer Apr 27 '18 at 13:18
  • oh, I didn't knew it was possible to split a request like this. How do you write it ? – ARn Lamourette Apr 27 '18 at 13:19
  • See the second link `:-)` – halfer Apr 27 '18 at 13:19
  • Thanks, I'll try and comeback later :D – ARn Lamourette Apr 27 '18 at 13:20

0 Answers0