2

The HTML looks like this:

<span class="MenuIcons searchButton"></span>
    ... (some stuff)
    <a data-bind="" url="/ParagonLS/Search/Property.mvc/Index/1" tabdescription="RESIDENTIAL" subtabdescription="Criteria" subtabmaxallowed="3" targetex="" rel="" class=" SearchByClass1 " subtabgroup="true" subtabgroupadd="true" subtabstartindex="0" fullwindow="False" hideaddressbar="False">TEXT</a>

I can get to the span using:

driver.find_element_by_css_selector(".MenuIcons.searchButton")

But since the span is a drop down menu I need to get to the inner element, but don't know how since it has spaces around its class name. What do I do?

3
  • I tried using xpath but since the spaces are in the class names I get errors. If you can show me how to deal with the spaces then, it is a possible solution. Commented Feb 24, 2015 at 4:40
  • can you select by link_text ? Commented Feb 24, 2015 at 4:46
  • I could, but I need to find a way to get it unhidden. Interacting with the website you do that by clicking the <span> element, then the drop down menu appears allowing the <a> element to be clicked. Commented Feb 24, 2015 at 4:50

2 Answers 2

2
import time
driver.find_element_by_css_selector(".MenuIcons.searchButton").click()
time.sleep(1)
driver.find_element_by_partial_link_text("TEXT").click()

You can do this and click the link.

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

4 Comments

I get "Unable to locate element: {"method":"link text","selector":"TEXT"}" error
@PythonNoob what is the link text exactly?
Thanks for the correction. I think this is much cleaner
@Saifur i guess he missed the click action before.I missed that too :)
1

I suggest you to use xpath instead since the class contains space.

//a[contains(@class,'SearchByClass1')]

Text based search is also another possibility.

//a[.='TEXT']

Edit Executing javascript since the element is hidden as per OP's comment

test = driver.execute_script("return document.querySelector(\"a[class*='SearchByClass1']\").innerHTML;");
print(test)

print

TEXT

12 Comments

Will this work with the <a> attribute originally being hidden?
don't think so. Is that hidden?
It is hidden under the <span> element. That is why I am trying to open it first, then the <a>
Can you execute javascript?
Thanx for the chat initiative :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.