简体   繁体   中英

C# Selenium Xpath

I am trying to select a an element from a DOM but I am struggling with. Basically i am trying to select a title attribute that contains some text. Below is a section of the DOM I am interegating:-

   <div id="map" class="leaflet-container leaflet-fade-anim" style="position: relative;"tabindex="0">
          <div class="leaflet-map-pane" style="transform: translate(-13px, 109px);">
                  <div class="leaflet-tile-pane">
                  <div class="leaflet-objects-pane">
                           <div class="leaflet-shadow-pane">
                           <div class="leaflet-overlay-pane"></div>
                           <div class="leaflet-marker-pane">
                                    <img class="leaflet-marker-icon leaflet-zoom-animated leaflet-                      clickable leaflet-marker-draggable" src="https://lgw-fids.ultra.aero/fids//Scripts/leaflet-0.7.2/images/marker-icon-red.png" title="DEMO Last Connected: 05/09/2014 12:01:41" tabindex="0" style="transform: translate(818px, 256px) rotate(0deg); z-index: 256;">
                                    <img class="leaflet-marker-icon leaflet-zoom-animated leaflet-clickable leaflet-marker-draggable" src="https://lgw-fids.ultra.aero/fids//Scripts/leaflet-0.7.2/images/marker-icon-red.png" title="Retest_Device_4 Last Connected: " tabindex="0" style="transform: translate(992px, 266px) rotate(180deg); z-index: 266;">
                                    <img class="leaflet-marker-icon leaflet-zoom-animated leaflet-clickable leaflet-marker-draggable" src="https://lgw-fids.ultra.aero/fids//Scripts/leaflet-0.7.2/images/marker-icon-red.png" title="AndyShort Last Connected: 08/09/2014 15:25:05" tabindex="0" style="transform: translate(629px, 221px) rotate(0deg); z-index: 221;">

So I am trying to select the 'img' element with a 'title' attribute that contains the text 'AndyShort'. I have tried this but it doesnt work:-

//div[@id='map']/div[1]/div[2]/div[3]/img[contains(text(),'AndyShort')]

Also,

//div[@id='map']/div[1]/div[2]/div[3]/img[@title contains(text(),'AndyShort')]

Can anybody help?

您应该检查标题属性

//img[contains(@title, 'AndyShort')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM