microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

WinAppDriver - Extract texts from image #1304

Open NadeemBader opened 4 years ago

NadeemBader commented 4 years ago

Hi

I'm able to located an item in my application which actually contains an image with texts (Located in different corners). I'm unable to access that texts (even not located by inspect.exe tool). Is that possible to extract that texts and the location of each text??

Best Regards, Nadeem Bader

anunay1 commented 4 years ago

if you are using python or java you can use driver self.driver.find_element_by_image()

NadeemBader commented 4 years ago

I'm using c#. Is that possible?

anunay1 commented 4 years ago

No.

NadeemBader commented 4 years ago

Ok - I understand. In general, is that mean that using WinAppDriver with Python is more powerful than using it with c#?

anunay1 commented 4 years ago

Depends on what do you want to achieve, so far this is the only difference what I have observed in different language bindings

NadeemBader commented 4 years ago

Ok - thank you very much

NadeemBader commented 4 years ago

Hi again - I'm trying to implement the "find_element_by_image" method using Python as shown below:

from appium import webdriver

desired_caps = {}
desired_caps["app"] = "Root"
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps)

element = driver.find_element_by_image("D:\\Form.png")
print("element", element)
print("rect: ", element.rect)
print("center_x: ", element.center_x, "center_y", element.center_y)
size = self.driver.get_window_size()
print(size)

But I get the following error message: "Message: Invalid selector: -image". Any idea? What is wrong in my code?

NadeemBader commented 4 years ago

It is appreciated to get some help here. I even tried the following code, but not working too:

file = open("D:\\Form.png", "rb");
content = base64.b64encode(file.read());
time.sleep(3)
element = driver.find_element_by_image(content)

Seems like a bad syntax of image path. Am I wrong?

anunay1 commented 4 years ago

This will not work with WinAppDriver server, please download the appium desktop, it works with that only,

manideepgithubinfy commented 3 years ago

I am also facing the same issue. Please find the below line I have tried to click on the image. _driver.FindElementByImage(imagePath).Click();

Note: First two executions I was able to click using above line of the code, do not have idea from 3rd exection onwords It was throwing the below mentioned exception. e = {"Invalid selector: -image"}