0

I've got a problem while trying to select a div tag class that has some white spaces in it.

This is the structure of page:

<div class="sadasd-dashboardtab even asdasd-syndicating_from_my_file" id="124121_1540012412412414">
    <div id="124121_154006585856856858">
        <span class="label">Syndicating From My File</span>
        <button class="column-dropdown" title="Click for more tab options"></button>
    </div>
</div>

This are my tries of code for this part:

#syndicating_button = driver.find_element_by_xpath("//span[text()='Syndicating From My File']")  
#syndicating_button = driver.find_element_by_xpath("//div[@class='yui3-dashboardtab even s-tab-syndicating_from_my_site']")
syndicating_button = driver.find_element_by_css_selector("div.yui3-dashboardtab.even.s-tab-syndicating_from_my_site")                                               
syndicating_button.click()
PyRar
  • 539
  • 1
  • 4
  • 21
  • 1
    Share exception – Andersson Oct 20 '18 at 21:59
  • This is the Exception @Andersson. NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"div.yui3-dashboardtab.even.s-tab-syndicating_from_my_site"} (Session info: chrome=69.0.3497.100) (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64) – PyRar Oct 20 '18 at 22:16
  • Add a wait... now does it work? – JeffC Oct 20 '18 at 22:37
  • Don't put relevant info in comments. Instead edit the question and add the relevant info there. If you did this in response to another's comment, @ mention them and tell them you've added the info they requested to the question. That way future readers don't have to read all the comments to get all the relevant info. – JeffC Oct 20 '18 at 22:38

1 Answers1

2

Your issue has nothing to do with "blanks"/"whitespaces" as your selectors should work well... if element is present in DOM. Try to wait until element appears in DOM and becomes clickable:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Syndicating From My Site']"))).click()
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • 1
    OK. Then check whether element is located inside an iframe (if HTML looks like ` – Andersson Oct 20 '18 at 22:36
  • Yes, it is an iframe! – PyRar Oct 20 '18 at 22:41
  • 1
    You need to [switch to iframe](https://stackoverflow.com/questions/7534622/select-iframe-using-python-selenium/48729644#48729644) before handling element – Andersson Oct 20 '18 at 22:44
  • If the iframe looks like this: "". How to search for it? – PyRar Oct 20 '18 at 22:54
  • 1
    Try `iframe = driver.find_element_by_xpath("//iframe[@src='fontTracker.htm']")` or the same with wait `wait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_xpath("//iframe[@src='fontTracker.htm']")))` – Andersson Oct 20 '18 at 22:55
  • This is the Exception I got: NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[@src='fontTracker.htm']"} – PyRar Oct 20 '18 at 22:59
  • 1
    Try to implement ExplicitWait as in my previous comment. Also note that iframe might be located in another iframe, so you have to switch to each iframe consequently – Andersson Oct 20 '18 at 23:01