0

I've a Selenium question.

I've tried, body y-axis position : driver.execute_script('return window.pageYOffset')

How to display y-axis position within a div?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
조광훈
  • 11
  • 1

1 Answers1

0

To display the x-axis and y-axis position of any WebElement e.g. the Search Box within Google Home Page you can use the following solution:

  • Code Block:

    driver.get("https://www.google.com/")
    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
    print(element.location)
    
  • Console Output:

    {'x': 439, 'y': 184}
    

To print only the y-axis you can use:

  • Code Block:

    driver.get("https://www.google.com/")
    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
    location = element.location
    x, y = location['x'], location['y']
    print(y)
    
  • Console Output:

    184
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352