Home > front end >  Selenium Python cant get style from div
Selenium Python cant get style from div

Time:01-02

Im having trouble getting the style of an element, anything I have tried I get TypeError: 'str' object is not callable, heres my code:

        movingavg_one = driver.find_element(By.XPATH('/html/body/div[2]/div[1]/div[1]/div[1]/div/table/tr[1]/td[2]/div/div/div[2]/div[2]/div[3]/div[2]/div/div[1]/div')).value_of_css_property('color')
        print(movingavg_one)

Heres the element enter image description here

I tried using getAttribute("style") and get_attribute("style") for some reason those also didn't work, im trying to get the color of the element, the element's color is the only thing that is in "style", so anything that will get the elements style will work. I have no idea what the problem is, but it's probably something really obvious that im missing.

CodePudding user response:

By.XPATH('By.XPATH('/html/body/div[2]/div[1]/div[1]/div[1]/div/table/tr[1]/td[2]/div/div/div[2]/div[2]/div[3]/div[2]/div/div[1]/div') using java here? (By.XPATH, "xpath") is python.')

Using Java here?

driver.find_element(By.XPATH, "xpath").value_of_css_property('color')

is the equivalent in Python.

  • Related