Note that there are some explanatory texts on larger screens.

plurals
  1. POXPath related questions to locate elements in Webdriver 2 Java
    primarykey
    data
    text
    <p>Dear Selenium Webdriver 2 Experts,</p> <p>I am new to this framework and need your advice on some XPath related questions on the following webpage XHTML snippet:</p> <pre><code> &lt;dl class="cN-featDetails"&gt; &lt;dt class="propertytype"&gt;Property type&lt;/dt&gt; &lt;!-- line 3 --&gt; &lt;dd id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_ddPropertyType" class="propertytype type-house" title="Property type: House"&gt;House&lt;/dd&gt; &lt;!-- line 3a --&gt; &lt;!-- or class="propertytype type-townhouse"---&gt; ....... &lt;div class="main-wrap"&gt; &lt;div class="s-prodDetails"&gt; &lt;a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_hypMainThumb" class="photo contain" href="/Property/For-Sale/House/LA/St Gabriel/?adid=2009938763"&gt;img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_imgMainThumb" title="44 Crown Street, St Gabriel" src="http://images.abc.com/img/2012814/2778/2009938763_1_PM.JPG?mod=121010-210000" alt="Main photo of 44 Crown Street, St Gabriel - More Details" style="border-width:0px;" /&gt;&lt;/a&gt; &lt;div class="description"&gt; &lt;h4&gt;&lt;span id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_lblPrice"&gt;Offers Over $900,000 &lt;/span&gt;&lt;/h4&gt; &lt;h5&gt;SOLD BY WAISE YUSOFZAI&lt;/h5&gt;&lt;p&gt;CHARACTER FAMILY HOME... Filled with warmth and charm, is a very well maintained family home in a quiet level street. Be...&lt;/p&gt; &lt;/div&gt; &lt;a id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_hypMoreDetails" class="button" href="/Property/For-Sale/House/LA/St Gabriel/?adid=2009938763"&gt;More Details&lt;/a&gt; &lt;dl id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_dlAgent" class="agent"&gt; &lt;!-- line 19 --&gt; &lt;dt&gt;Advertiser&lt;/dt&gt; &lt;!-- line 20 --&gt; &lt;dd class="contain"&gt; &lt;!-- line 20a --&gt; &lt;!-- or class="" --&gt; &lt;img id="ctl00_ctl00_Content_Content_SrchResLst_rptResult_ctl04_lstTemplate_imgAgencyLogo" title="Carmen Jones Realty" src="http://images.abc.com/img/Agencys/2778/searchlogo_2778.GIF" style="border-width:0px;" /&gt; &lt;/dd&gt; &lt;/dl&gt; &lt;/div&gt; </code></pre> <p>( a ) How to test whether an element exist or not? e.g. either line 3 or 3a exist but not both. The findElement() method will cause an exception which is what I am trying avoid. Another option is use findElements() before checking whether its collection list result is empty or not. This approach seems to be a long winded way of doing it. Are there any other simpler way to validate the existence of an element without the risk of causing an exception? The following statements did not work or cause exception:</p> <pre><code>WebElement resultsDiv = driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/h1/em")); // If results have been returned, the results are displayed in a drop down. if (resultsDiv.isDisplayed()) { break; } </code></pre> <p>( b ) Is there a simple way to validate the existence of either of the elements by incorporating boolean operator, and regex, as part of the findElement() or findElements()? This would significantly reduce the number of finds as well as simplifying the search.</p> <p>( c ) Is it possible to use XPath syntax when searching Element by TagName. e.g. driver.findElement(By.tagName("/div[@class='report']/result"));</p> <p>( d ) Is it possible to use regex in XPath search such as driver.findElement(By.xpath("//div[@class='main-wrap']/dl[@class='agent']/dd[@class='' OR @class='contain']")) for line 20 - 20a?</p> <p>( e ) How to reference the immediate following node? e.g. Assuming the current node is <dt>Advertiser </dt> on line 19, how to lookup title of which is under , where its class name can have a value of "contain" or nothing "". There could potentially be multiple tags within on line 18.</p> <p>I have use XPath on XML document in the past but would like to expand the ability to locate elements within Webdriver 2. </p> <p>Any assistance would be very greatful.</p> <p>Thanks a lot,</p> <p>Jack </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload