You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if you want to upload a file to an element in Pylenium, you use the .type() command since that wraps .send_keys() from Selenium. Although it works, it's not explicit or intuitive. Instead, we should have an upload() command!
# Current solutionpy.get("[input='upload-image']").type("path/to/file.png")
Solutions
I recommend adding a new .upload() method to our Element class!
Solution
# Something like this under the Element classdefupload(self, filepath: str) ->"Element":
returnself.type(filepath)
With a solution in place, focusing on an element feels much more explicit and makes sense 🎉
My current understanding is that you can only upload files to <input> elements. We could add a check to make sure the element is an <input> first and raise an error if it's not. The helpful error could save some headache, but this is something we should into a bit more.
The text was updated successfully, but these errors were encountered:
It seems the main benefits to using Element.upload() instead of Element.type() is:
upload(filepath: str) is more intuitive and explicit than type(*args)
Better logging since it would be clear that you performed an "upload" action instead of typing into something which could be confusing
However, the biggest drawback I ran into in designing and implementing this is that you still need to click() or submit() some "Upload Button" to complete the upload. This may not be as big a deal, but I was hoping that I could find a way to do both actions in a single command. The only thing that came up (so far) was something like the snippet below, but it didn't feel great to use:
Problem
Currently, if you want to upload a file to an element in Pylenium, you use the
.type()
command since that wraps.send_keys()
from Selenium. Although it works, it's not explicit or intuitive. Instead, we should have anupload()
command!Solutions
I recommend adding a new
.upload()
method to ourElement
class!Solution
With a solution in place, focusing on an element feels much more explicit and makes sense 🎉
Considerations
My current understanding is that you can only upload files to
<input>
elements. We could add a check to make sure the element is an<input>
first and raise an error if it's not. The helpful error could save some headache, but this is something we should into a bit more.The text was updated successfully, but these errors were encountered: