1

I am trying to find the xpath of the element below, so that I can later get the text using Ruby Selenium-webdriver (ie. helloPage.mainHeader.get_text).

<div class="container">
  <div class="template-section">
    <div class="front">
      <h3 class="containerHeading">
      <i class="icon_image"></i>
      "Hello world   <-----------------------3 whitespaces
      "
      </h3>
    </div>
   </div>
</div>

I've worked on xpaths but everytime I rerun the test it timesout essentially the element does not exist. It is clearly visible on the UI and not hidden.

Why is my xpath is wrong? I have tried the following:

  1. //div[@class='container']//div[@class='template-section']//div[@class='front']//h3[@class='containerHeading']
  2. //div[@class='front']//h3[@class='containerHeading']
  3. //h3[@class='containerHeading']

I did put sleep prior to executing helloPage.mainHeader.get_text, where mainHeader has the XPath expression, and that didn't work. Is there something mysterious about the Hello World text? The format is indeed like the way I typed it out.

4

1 回答 1

0

您所有的 xpath 对我来说似乎都是正确的...我认为当您尝试使用 xpath 查找元素时...元素未正确加载...尝试使用显式等待。请尝试使用下面提供的代码:

    等待 = Selenium::WebDriver::Wait.new(:timeout => 10)
    wait.until { driver.find_elements(:xpath, "你上面提到的任何 xpaths") }

于 2013-09-10T08:28:17.270 回答