filmov
tv
Use ChatGPT to Generate Selenium Python Code Specific to Your Webpage
![preview_player](https://i.ytimg.com/vi/kjUvs9qCC8k/maxresdefault.jpg)
Показать описание
I used ChatGPT’s help to complete a small selenium task. It definitely saved me an hour of work, but I'd also wasted an hour trying to get thru some of ChatGPT's frustrations. All in all, I broke even. However, like any tool, practice is required to gain efficiency. In this video, I go over a few tips to help you get started and work more efficiently with ChatGPT and hopefully minimize the frustrating parts.
-Let ChatGPT take the first cut. Maybe you have a task but haven’t thought about how to do it yet. Now would be the best time to let ChatGPT do your initial thinking.
-How do you get ChatGPT to write Selenium code if it can't go to your webpage? Using Chrome Dev Tools, you can copy the HTML of the target element and feed it to ChatGPT. If the element has an ID, Selenium can find the element without knowing its parent or ancestor elements. You could feed the whole HTML page to ChatGPT, but there is a character limitation on the input box, and the more information you feed it, the more likely it will get confused. So it’s best to limit the scope as precisely as possible.
-ChatGPT has outdated knowledge. ChatGPT has knowledge up until 2021. It just so happens that the Selenium library depreciated and stopped supporting some commons functions, like find_element_by_id, after 2021. Be prepared to make some corrections to the code it generated for you.
-Assume the code is wrong. We should be aware that, in its current state, ChatGPT is wrong a lot, so it's still up to us to make sure the code is correct. Just because it runs and the output looks good doesn't necessarily mean there are no potential bugs.
-Don't get lazy or overly reliant on ChatGPT. While using ChatGPT to generate Selenium code, I found myself asking it to generate code for simple things that I could have done and should have done myself.
-Know when to cut your losses: I would have liked ChatGPT to continue building upon the code it initially generated for me. However, after a few exchanges, it started spitting out code that looked drastically different from before. At some point, you have to accept that ChatGPT isn't going to produce what you need. So instead of wasting more time, it's best to move on.
-Take opportunities to learn from ChatGPT. It generated code that uses the Python zip() function, which I was unfamiliar with. I asked "what is zip" and it gave a nice explanation.
Комментарии