2

I have recently started using Selenium to test an app having webviews. Well the code for my webview is:

<div class="class1 class2 class3 class4" style="padding: 4px;" id="_6bd7b91a-214c-4075-b7db-dcaa08155e1a"> 
    <span class="class5" style="font-weight: bold; text-decoration: underline;">This is TITLE</span> 
    <div class="class6" dd:contenttype="content_type1" dd:concept="TITLE" id="_1d8c4490-d0c1-42ed-a93e-e92ca570dd32">
     <div class="class7"> 

I am writing a re-usable code to find the element for automation testing. In the above code, element can be found using 2 ways, I can look for it based on 'dd:concept="TITLE"' or through the text "This is TITLE"; but I could not find anything in Selenium using which I can find the element the way I want to.

I am using "find_element" to look for an element, but there is nothing to which I can pass 'dd:concept="TITLE"' or "This is TITLE" as an arguement.

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

Is there anyway I can find the element on the webview using Selenium driver and some text as its arguement??

1 Answer 1

2

FindElement(By.CssSelector("[dd:concept='TITLE']")) should work.

Ah, you're using ruby.

I did a bit of looking, you could try this:

find_element(:css, "[dd:concept='TITLE']")

Edit once again.

I would suggest escaping the : in the tag name dd:concept, like this:

find_element(:css, "[dd\:concept='TITLE']")

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

5 Comments

Thanks Richard!! But it didn't help me a lot. I am doing $driver.find_element(By.CssSelector("[dd:concept='TITLE']")) and its giving me "NameError: uninitialized constant By from (pry):3:in `block (3 levels) in <top (required)>'" error.
I guess the only arguments find_element is taking is one of these - (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)
I tried that way. Am getting "Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command." error
With some google search I found I can use this - driver.find_element(:css, "div.ddsection ddrefreshable ddinsertfreetext ddremovable span.ddsectiondisplay"). But even this didn't work for me.
This worked for me. It wasn't working yesterday as for some reason I was not getting the required text inside the dom.

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.