1

I am trying to find a element using Selenium in Python that has the html like this:

<td class="td1" onclick="window.location.href = 'work_area.php?SID';">Work area</td>

Contained in a simple <tr></tr> tag.

I have tried using

work_area = driver.find_element_by_css_selector('td[contains(@onclick, "work_area.php?SID"]')

and using an absolute xpath

work_area = driver.find_element_by_xpath("/html/body/table/tbody/tr[2]/td[1]/div/table/tbody/tr[2]/td/table/tbody/tr[3]/td")

My buttons structure:

+---------------------+
|       Menu          |
+---------------------+
|     Work Area       |
+---------------------+
|     Details         |
+---------------------+

I am using Python 3.6, and Selenium is up to date, any suggestions? I have also tried different suggestions that I could find on stackoverflow but nothing helped.

Julanu
  • 162
  • 2
  • 5
  • 15
  • 1
    *"I have also tried all the versions"*... which exactly? – Andersson Sep 05 '18 at 18:07
  • https://pastebin.com/fpsesdyc Here, these are "all the versions" that were suggested or refered to similar problems, that I could provide links for* – Julanu Sep 05 '18 at 18:09
  • No, I mean your implementation. What else you've tried instead of just locate element? Share the code – Andersson Sep 05 '18 at 18:12
  • I have only tried using Selenium, I know about BeatifulSoup and other modules. I will edit :) – Julanu Sep 05 '18 at 18:14
  • Did you try Explicit/Implicit wait? Did you check whether element is located inside an iframe? – Andersson Sep 05 '18 at 18:16
  • yes, I have tried using Explicit/Implicit wait but they didn't seem to work, the website is build pretty bad and a lot of things are unclear in their code, thats why I couldn't figure it out. And no, it's not located inside an iframe – Julanu Sep 05 '18 at 18:20

1 Answers1

4

You can use locators below:

driver.find_element_by_css_selector("td[onclick*='work_area']")
driver.find_element_by_xpath("//td[.='Work area']")

You code below wasn't correct, locator is xpath and you use css selector:

work_area = driver.find_element_by_css_selector('td[contains(@onclick,"work_area.php?SID"]')
Sers
  • 12,047
  • 2
  • 12
  • 31