1

HTML:

<g id="OpenLayers.Layer.Vector_101_vroot">
    <image id="OpenLayers.Geometry.Point_259_status"..></image>

So the page generates the above and the number section of the Id is different on each load.

How do I located them, or even a group of them that match the pattern using selenium and python?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Tomy
  • 67
  • 1
  • 9

3 Answers3

1

Use Xpaths like below:

//g[contains(@id, 'OpenLayers.Layer.Vector')]
//image[contains(@id, 'OpenLayers.Geometry.Point')]

Hope if helps!

Sitam Jana
  • 3,123
  • 2
  • 21
  • 40
  • If I already have the element that Contains the element should I be using // or .// ? thanks – Tomy Aug 22 '14 at 08:57
  • You can use : //g[contains(@id, 'OpenLayers.Layer.Vector')]/image[contains(@id, 'OpenLayers.Geometry.Point')] – Sitam Jana Aug 22 '14 at 09:21
0

no need for and pattern matching, you can use this module here called "beautiful soup" with some easy documentation here.

for example to get all tags with id="OpenLayers.Layer.Vector_101_vroot" use:

soup = BeautifulSoup(<your_html_as_a_string>)
soup.find_all(id="OpenLayers.Layer.Vector_101_vroot")
Ishan Khare
  • 1,745
  • 4
  • 28
  • 59
  • Thanks for the reply but BeautifulSoup appears to be a parser, im usuing selenium it interacts with a broweser as a person would. Thanks – Tomy Aug 22 '14 at 09:09
0

according to this answer, you can use css3 substring matching attribute selector. the following code clicks an element which contains OpenLayers.Layer.Vector in id attribute.

Python

from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://localhost:1111/')
browser.find_element_by_css_selector('[id*="OpenLayers.Layer.Vector"]').click()

HTML (which is displayed in http://localhost:1111/)

<button id="OpenLayers.Layer.Vector_123" onclick="alert(1);return false">xxx</button>
Community
  • 1
  • 1
ymonad
  • 11,710
  • 1
  • 38
  • 49