12435432nm
12435432nm

Reputation: 131

How to locate the x, y coordinates of text on the screen?

I am trying to find the x, y coordinates of a web element (part of the web page that's open on screen) and some automated tests using the robotframework are being run on it.

I'd like to provide the function with the text string, and get (x, y) coordinates returned.

I am not sure if I can do this in pyautogui.

Environment: Chrome / OS X

EDIT:

I am wondering if I can use locateOnScreen() function in this library to locate text, (but it seems it's only for images according to the documentation)?

Upvotes: 1

Views: 6629

Answers (1)

Satish Prakash Garg
Satish Prakash Garg

Reputation: 2233

Web elements has property .location which return dictionary of x and y coordinates of the element.

driver = webdriver.Chrome('/path/to/chromedriver')
elem = driver.find_element_by_xpath('//xpath_to_the_element')
loc = elem.location
print(loc)

Above code will return something like :

{'x' : 123, 'y' : 234}

Upvotes: 3

Related Questions