0

I've tried manipulate some website with selenium. Unfortunately, I've encountered problem to go further.

After opening the website I need to select one element and execute click event. I've tried with find_element_by: name, tag_name, class_name, but every time I've received massage "There's no such element". Inspection of this element gives this output:

<div 
style="position: absolute; left: 90px; top: 3px; width: 48px; height: 18px; text-align: center; cursor: pointer; font-family: tahoma; font-size: 11px; font-weight: normal; border-top: 1px solid rgb(85, 85, 85); border-left: 1px solid rgb(85, 85, 85); border-right: 1px solid rgb(85, 85, 85); padding-top: 5px; background-color: rgb(117, 148, 159); border-radius: 4px 4px 0px 0px; color: rgb(255, 255, 255);"
>Działki</div>

How to select this element with selenium (python)

UPDATE:

I thought xpat is solution and partially that's true

Now I've tried this:

browser.find_elements_by_xpath("/html/body/div[3]/div[8]/div[2]/div[1]/div[4]").click()

... but now I've got this:

AttributeError: 'list' object has no attribute 'click'

What is wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
data_b77
  • 415
  • 6
  • 19
  • _I've tried with find_element_by: name, tag_name, class_name_ This `
    ` element has no name nor class. I'm confused how you would search by those attributes.
    – John Gordon Jun 18 '19 at 19:14
  • Using find_element_by_tag_name('div') finds the first
    element. Is that not working or is there something else you are looking for?
    – Deepstop Jun 18 '19 at 19:16
  • I think you can try to use xpath, like this: driver.find_element_by_xpath(xpath). xpath can be obtained from right click on the element in the inspector menu – Leo Skhrnkv Jun 18 '19 at 19:17

2 Answers2

0

If you know what the div will contain but don't have a class or name, you could try to identify it by its internal contents. For your example that would be "Działki"

This answer explains how to do this: How do I find an element that contains specific text in Selenium Webdriver (Python)?

Alex B
  • 1
  • 2
0

If you know the text in the div and it's unique you can locate it with text().

It will look something like this:

browser.find_elements_by_xpath("//div[text()='Działki']")

Hope this helps you!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38