Home > Software design >  I can't find the error and no error is displayed
I can't find the error and no error is displayed

Time:07-26

I would like the value from the page to be output with the print() command, but unfortunately no value is output and no error is displayed.

webseite: https://coordvert.com/en/koordinaten-umrechnen/utm/dezimalgrad?utmzone=-1N&utme=668184.607&utmn=0.000

This is the code:

breitengrad = driver.find_element_by_xpath('(//div[@])[4]/input').text

print(breitengrad)

CodePudding user response:

That element you are looking for (breitengrad) appears to have an ID, so it's more robust to just locate it by ID. Also, if you are using Selenium 4, the find_element_* method was deprecated in favour of find_element(By.*,...). The following code will accept the cookies in case the initial pop-up shows up, wait for the page to load, locate the breitengrad and print out the value:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


chrome_options = Options()
chrome_options.add_argument("--no-sandbox")

webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary
browser = webdriver.Chrome(service=webdriver_service, options=chrome_options)

url='https://coordvert.com/en/koordinaten-umrechnen/utm/dezimalgrad?utmzone=-1N&utme=668184.607&utmn=0.000'

browser.get(url) 

try:
    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Alles Akzeptieren']"))).click()
except Exception as e:
    print('no pop-up, moving on')

breitengrad = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "cov-2-lat")))
print(breitengrad.get_attribute('value'))

This returns the value of that input field:

0

CodePudding user response:

Thank you for the quick help, the problem was solved with your answer.

  • Related