2

I have this code for which I am doing automation testing using ruby.

<div class="class1 class2 class3 class4" style="padding: 4px;" id="_d4b99a9f-d1c8-4587-94e2-5ee95ebf1f76"> 
    <span class="class5" style="font-weight: bold; text-decoration: underline;">This is new TITLE</span> 
    <div class="class6" dd:contenttype="TEST CONTENT TYPE" dd:concept="TITLE" id="_7cfd6eed-fa15-42b8-81af-d09bf3cd4460">
     <div class="class7"> 
      <div class="class8" dd:contenttype="TEST CONTENT" dd:entityid="0" dd:entityversion="0" id="_1c9125c4-b078-4017-a5ad-c48210e7090b"> 
       <div class="class9 class10" dd:btnfloatingstyle="top-right" dd:entitytexttype="resultval" id="_9c41159a-3a5b-4de1-87d2-e3361bd4d746" contenteditable="true"></div> 
      </div> 
     </div>
    </div> 
   </div> 

I want to search the element using either 'This is new TITLE' or 'TITLE' for which I tried find_element with css selector and also with xpath but none seemed to work for me.

driver.find_element(:css, "span.class5") or `driver.find_element(:css, "div.class1 class2 class3 class4 span.class5")` 

Nothing seemed to work for me. Am I missing something?

3
  • Is this question different than your previous one - Find elements using Selenium Webdriver? Commented Jul 29, 2013 at 21:25
  • Just trying to be more specific with the question. Commented Jul 29, 2013 at 21:27
  • If you are clarifying the question, you should edit the existing one rather than creating a new one. Commented Jul 29, 2013 at 21:28

2 Answers 2

0

Yes,you can do that using selenium-webdriver and :xpath. Take a look at the below example:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://en.wikipedia.org/wiki/Ruby_(programming_language)"

driver.find_element(:xpath,"//span[@class = 'mw-headline' and text() = 'Ruby 1.0' ]").tag_name
# => "span"
driver.find_element(:xpath,"//span[@class = 'mw-headline' and text() = 'Ruby 1.0' ]").text
# => "Ruby 1.0"

This example is fully equivalent to your html code. Now try to create your xpath,by taking the help of the above. You will get success.

Sign up to request clarification or add additional context in comments.

Comments

0

Use nokogiri gem

require 'nokogiri'

$page_html = Nokogiri::HTML.parse(browser.html)

$page_html.css("span.ddsectiondisplay").text
=>"This is new Title"

Or if you're just using watir.

browser.title
=>"title of page" 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.