Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category selection sometimes fails #2

Open
fpinchon opened this issue Oct 20, 2022 · 4 comments
Open

Category selection sometimes fails #2

fpinchon opened this issue Oct 20, 2022 · 4 comments

Comments

@fpinchon
Copy link

fpinchon commented Oct 20, 2022

The category selection sometimes fails because the category is not scrolled on the screen. Manually scrolling the categories until the one it's trying to click on is visible solves the issue. It would be nice if the script itself tried to scroll until the category it wants is on screen. Can this be done with selenium?

(Also I have to mention that everything else works perfectly, thank you so much for this!)

@YungBricoCoop
Copy link
Owner

I think the problem comes from the category name and not from the visibility of the category on the page. There was a piece of code that removed the spaces in the category name (so the script could never find them on the page with the xpath because the space was missing). I fixed that and still added the scroll to the category before clicking on it.

[Don't forget to star the repo if you liked it :) ]

@fpinchon
Copy link
Author

fpinchon commented Oct 20, 2022

I had no issues with the category names on my side. The script just sometimes worked, and sometimes would fail.
Today I investigated a bit more the issue, and saw that this tends to happen more frequently when opening many pages (setting a high number of iterations).
What's happening is that the category pictures take A LOT of time to load when multiple pages are open (my computer is getting quite old), and the website is coded in such a way that nothing (even the input field) is interactable until most buttons' pictures are fully loaded.

I see two ways of solving this issue:

  • The first solution would be to increase A LOT the timeout values for the first step, the one where we wait for the textfield to be clickable. (This is what I've done on my side, it's not ideal but it works).
  • The second solution would be to do a major refactor:
    Ask first the amount of pages to open, then open them and wait for the input field to be clickable.
    When the pages are all ready, ask for a new job (prompt, category and other job parameters you might add in the future). Send this job to all the threads, then wait for the job to be completed on all pages. When the pages are all ready again, ask for a new job.
    Basically, open the pages first, then ask for jobs repeatedly, using the same pages opened instead of opening new pages everytime (losing time opening up the pages again, chrome is quite slow and takes a lot of resources).

If I find some time I'll try to do that on my side. If I manage to pull it off, I'll make a pull request.
However, if you feel motivated, feel free to do this yourself, you'll probably do it a lot more efficiently!

[Edit: I starred your repo :)]

@YungBricoCoop
Copy link
Owner

I refactored the code based on the second solution you suggested (very good solution in my opinion). However I don't wait until all categories are loaded because I didn't find a good way to do that. Now when the script is launched we are asked how many instances to launch (chromium instances). Then we are asked what we want to generate (we can indicate several elements by separating them with commas). We can also indicate that we want to create several iterations of an element by adding a # with the desired number (example: chicken#5 ). Then we are asked which styles to use (we can indicate several styles by separating them with commas). I tried to generate 15 elements with 2 different styles on 10 instances and everything worked correctly.

Could you please try and give me a feedback to see if it fixes the problem you had. Thanks in advance

But I still have to modify the documentation accordingly.

@YungBricoCoop
Copy link
Owner

@fpinchon did you have time to test the new version of the script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants