Playwright finds too much elements by text - playwright

I tried to find all the elements that has the text "Operation" inside them. I only see one such element visible, but Playwright is giving me 19:
self.page.locator('*', has_text='Operation').click()
When I run this selector in the developer tools:
$x('//*[contains( text(),"Operation" )]')
I see only a single element.
What am I doing wrong here?

You can use the text locator and also add more Texts along with Operation to pinpoint your element more accurately.
page.locator("text=Operation").click()
page.locator("text=Some more words Operation").click()
Or, you can also use the Nth element selector if you know the position of the text occurrence. Starts from 0
page.locator("text=Operation >> nth=0").click()

Related

Styling specific line of Text on Jetpack Compose

So, it's kind of a simple styling.
Text(
text = "some text which can extends to many lines"
)
how would someone build an annotated string to style only specif lines of the text? And by line I mean what it's actually rendering as a line - and not something predefined as a list of sub strings.
I've imagine to make a use of combined textLayoutResult with the annotated capability, but by reading the documentation I don't have much clue how to do so.
The plan was to the TextLayoutResult to retrieve the number of lines rendered on text. Then, it should be theoretically possible to retrieve the sub string on each of the lines rendered. And by pushing them on the annotated processor, the desired results would be achieved.
What am I missing?
I've managed to achieve the desired effect.
For those who want to do, you will need at least:
Two Text components;
A mutable state to keep track of offset on the text;
You limit the first Text by the number of maxLines - 1 and uses TextLayoutResult to retrieve the last offset of the last line. Then, you just update the state on the composable and create another Text component with the substring which starts from the last one. Then, you can apply the filters that you wish on this one.
Repeate the process for as many lines as you wish.

Is there a way to automatically feed a label after each print, then automatically backfeed that fed label before the next print in Zebra printers?

I apologize for the long title, but that is exactly what I am trying to achieve.
I'll try to explain more briefly here:
So I have a Zebra ZT610 with a scanner that checks every single label as they are printed. The problem is that we're trying to print labels solely, not in batch, and the issue with that is that the printed label will always be in a position where an operator will not be able to take the label without destroying it. The issue with this is it will become a waste of labels and ribbons if this process remains as is.
How it is now (it is not really in production, but to give you an imagination):
Operator clicks on print
Zebra prints a label (and the scanner checks the label simultaneously)
Operator feeds a label (in order to take the label without destroying it)
Operator takes the label
Repeat the process
That is the issue, in theory we would have to waste HALF of the amount of available labels (assuming that all printed labels passed the inspection) in order to finish the job, which is definitely absurd and no one in the world would do this hahah
What we're trying to achieve:
Operator clicks on print
Zebra prints a label (and the scanner checks the label simultaneously)
The printer feeds a label automatically (or maybe half of a label at least for the printed label to be taken without any issue or destroying it)
Operator takes the label
Operator prints another label
Printer backfeeds the latest fed label
Printer prints on the backfed label
Continue on from step 3, and so on.
I searched for anything related to this and all what i found was this:
^XA
^FD
^XZ
All it basically those is "print" a space on a label, thus technically feeding a label. But i was never able to get that label to go back inside the printer.
Thank you for reading this far.
EDIT:
We have also tried this:
Went into the printers settings via its IP address and login
Click on 'View and Modify Printer Settings'
Click on 'General Setup'
Below you will find 'Tear Off Adjust', we've set it to the maximum (120) but that was not enough, it is still too far inside.
But i hope the solution above helps other people out there.
Take a look at the ~JS command - Change Backfeed Sequence. By overriding the default backfeed, you can force the label media to feed forward after printing, then retract on the next print.
Not knowing how much backfeed you will need, start with 50% (~JS50) and adjust from there.

How to clear the output in a cell in itorch notebook?

In itorch notebook, Is there a way to clear the output of a cell with code?
What I would like to do is to dynamically display the progress, like a loading bar.
The reason for this is when a lot of computation is involved, I would like to track how far the progress has gotten, and whether it froze or not.
So basically I would like to print the number of iteration I'm in in percentage form and overwrite it in the next iteration.
Any ideas?
You can use the carriage return character (\r) to overwrite the same line in a cell.
For example:
io.write("Hello") -- No newline
io.write("\rWorld")
just displays
World
You can use this to write several times the progress of your process, without adding multiple lines.

How do you rotate a text

There is a video on how to rotate an object around a point but I fail to select the text.
I wanted to do the same thing and saw your question before figuring this out.
1. The "Geogebra Way"
In the Algebra Perspective enter the following RotateText commands in the Input box at the bottom:
RotateText["Rotated text using degrees.", 45°]
RotateText["Rotated text using radians.", 0.785398]
In the Construction Protocol view, this is represented by
"rotatebox{45}{ \text{Rotated text using degrees.} }"
"rotatebox{44.9999999}{ \text{Rotated text using radians.} }"
Note that the radian form of the RotateText command is converted to degrees in the construction step. So this creates an graphical object that renders the text in a LaTeX "rotatebox". It's rather strange that the system doesn't have a tool to create rotateable text.
You can attach the text to an object via the object's Properties->Position->Starting Point. Only certain types of objects can be used, and the text can only be placed/moved underneath the object, which is odd. You can get around this by creating a line segment, attaching the rotateable text object to a desired end-point on the line segment above the location you want the final text, and then hiding the line segment.
2. A better, "undocumented" Geogebra method!
One can actually use LaTeX in captions of objects. Here's how you would enter the text:
$\rotatebox{45}{ \text{Rotated text using standard text box!} }$
A nice thing about this is the caption can be easily placed above the object. Notice that LaTeX commands are surrounded by the dollar sign. Also notice that there is a backslash as part of the \rotatebox command.
Also, one can use the standard text tool to do the same thing. This has the advantage that the text can be dynamic! Create some text anywhere. Then edit it's properties on the Text tab. Check the LaTeX checkbox, and enter the following for the text:
$\rotatebox{45}{ \text{} }$
Then inside the \text{} brackets, select an object. The text will be updated with the object's value. Or a combined form:
$\rotatebox{45}{ \text{"The value is:" + SliderObject} }$
I've tried to put an object in the "degreees" field, but could not get that to work.
Use the RotateText command like this:
RotateText("What ever text you want", angle)

kCTParagraphStyleSpecifierParagraphSpacing not respected for first line of a CTFrame

We have an app that is dependent heavily on kCTParagraphStyleSpecifierParagraphSpacing to manage spacing between paragraphs, which can vary throughout a body of text. For editing performance, we implemented our main Core Text view as a collection of CTFrames that are drawn/redrawn when appropriate.
We've found that if a paragraph uses a nonzero kCTParagraphStyleSpecifierParagraphSpacing as one of its CTParagraphStyleSettings attributes, this paragraph spacing is ignored if that paragraph is the first item in a CTFrame, even if there is a another paragraph preceding it in the text fed to the framesetter.
I suppose this behavior makes sense if you're drawing to a PDF intended to be printed, but given that we're trying to present our text a a single, scrollable and contiguous block of text, it is giving us problems. Is there any way to work around this problem?
If you can't change the behavior with a CTParagraphStyleSetting, I think it's a bug, or Apple thinks that behavior makes sense. Anyway, to get the result that you desire, I think the best way is to use CTTypesetter and handle lineSpacing and paragraphSpacing yourself. I think the CTFrame implementation is quite buggy, as I just run into another not long ago.
For rolling your own solution, you will need CTTypesetterSuggestClusterBreak or CTTypesetterSuggestLineBreak to calculate char count of each line. Line height can be the font size, and you add lineSpacing when drawing each line. When you encounter a newline(\n) character, add paragraphSpacing before drawing next line.
With CTTypesetter, things are more controllable, of course, it also adds some difficulties since you have to handle line breaks and indentation. But this is the only way I can think of to get a more desired result.
Good luck.

Resources