Region contains 100 clickable link. How can I will be able to click a link based on Plain text pattern

Asked by Anup K on 2019-11-25

Region contains 100 clickable link. How can I will be able to click a link based on Plain text pattern.

Region have below links:
sports
news
.
.
.
sports1
news1
.
.

Expectation from Sikulix :
If I pass a variable like "sports1". It should click on the link having caption "sports1".

Region.find() or Region.click() does not able to recognize sports1 link (say Region.click("sports1")) . However if I take screenshot of "sports1" from Sikulix editor (say screen shot holding reference of 123.png) Region.click("123.png") is working fine.

Region Documentation:
Click() can accept image path or just plain text. Here I am using plain text. Am I misinterpreting documentation language. Please suggest.

Thanks in advance RaiMan :)

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-11-28
Last query:
2019-11-28
Last reply:
2019-11-27
RaiMan (raimund-hocke) said : #1

SikuliX version?

send me a screenshot to sikulix---at---outlook---dot---com

Anup K (anupk) said : #2

Thanks RaiMan.

Version details:
IDE version 2.0.0
sikulix-2.0.0.jar
sikulixapi-2.0.0

Email has been sent with screen shot subject "Region contains 100 clickable link. How can I will be able to click a link based on Plain text pattern"

Please have a look and let me know in case of more information.

Region.click("Sports") or Image.click("Sports") not working.

Anup K (anupk) said : #3

If you got any chance to look into it please provide the approach to fix the issue. Thanks!!

RaiMan (raimund-hocke) said : #4

Tried with 2.0.x:

r = Region(224,107,76,170)
print(r.text())
m = r.findText("test3")
m.click()

Having your image visible on the screen in the Region r, it works for me.

Anup K (anupk) said : #5

If I am applying html font like below. its not working. But if I delete the a{font....} style its working fine.

Save below snippet as "fontStyle.html":

<!DOCTYPE html>
<html>
<head>
<style>
a {font-family:Tahoma, Verdana, Helvetica, sans-serif;font-weight:normal;font-size:11px;color:#003399;text-decoration:none}
</style>
</head>
<body>
<h2>HTML Links</h2>
<p>HTML links are defined with the a tag:</p>
<a href="https://www.w3schools.com" style="anchor">This is a link</a><br>
<a href="https://www.w3schools.com">Test</a><br>
<a href="https://www.w3schools.com">test2</a><br>
<a href="https://www.w3schools.com">test3</a><br>
<a href="https://www.w3schools.com">test4</a><br>
<a href="https://www.w3schools.com">test5</a><br>
<a href="https://www.w3schools.com">Sports</a><br>
<a href="https://www.w3schools.com">News</a><br>
<a href="https://www.w3schools.com">NewsTest</a><br>
</body>

Anup K (anupk) said : #6

Is there any way to train the font or any other approach. Please help.

Best RaiMan (raimund-hocke) said : #7

--- alternative approach to findText()
you can try the following, since your links are arranged as some lines in a Region:

reg = someRegion # to be defined somehow

lines = reg.collectLines()
# lines is a list of Match objects, one for each line found

for line in lines:
    print line.getText() # here you could check the line content as text
    #line.hover() # and click it in case

--- Is there any way to train the font or any other approach.
yes, Tesseract is trainable. You have to create your own *.traineddata file and make it accessible to SikuliX.
For the HowTo you have to dive into Tesseract and its training tools (see Tesseract home page).
More I cannot do for you, since this is far beyond the scope of SikuliX.

Anup K (anupk) said : #8

Thanks RaiMan. I will catch you up for further issue.
its solved my problem and got some way around of it.

Anup K (anupk) said : #9

Thanks RaiMan, that solved my question.