Home > Mobile >  I wan't to use get_attribute in a value but don't have 'data_value' just number,
I wan't to use get_attribute in a value but don't have 'data_value' just number,

Time:09-26

I'm using in my code the library Selenium in Python, but I can't get the value in a page with inspect google.

primeiro_value = nav.find_element_by_xpath('/html/body/main/div[2]/div[2]/ng-view/div/div[2]/div[1]/div[1]/div/div/div/div[2]/div[2]/div/div[1]/div/div[6]/div').get_attribute()

enter image description here enter image description here

CodePudding user response:

You are using .get_attribute() without any attribute.

If your sole purpose is to get 240.558 and this xpath /html/body/main/div[2]/div[2]/ng-view/div/div[2]/div[1]/div[1]/div/div/div/div[2]/div[2]/div/div[1]/div/div[6]/div represent the div which has that numric value, you could do the following to get the value

primeiro_value = nav.find_element_by_xpath('/html/body/main/div[2]/div[2]/ng-view/div/div[2]/div[1]/div[1]/div/div/div/div[2]/div[2]/div/div[1]/div/div[6]/div').get_attribute('innerHTML')
print(primeiro_value)

or

primeiro_value = nav.find_element_by_xpath('/html/body/main/div[2]/div[2]/ng-view/div/div[2]/div[1]/div[1]/div/div/div/div[2]/div[2]/div/div[1]/div/div[6]/div').get_attribute('innerText')
    print(primeiro_value)

or

primeiro_value = nav.find_element_by_xpath('/html/body/main/div[2]/div[2]/ng-view/div/div[2]/div[1]/div[1]/div/div/div/div[2]/div[2]/div/div[1]/div/div[6]/div').text
    print(primeiro_value)
  • Related