Hướng dẫn dùng python selector python
1. Import the Selenium libraryYou can get Selenium from here. Show
2. Start the webdriver and the browserStarting the webdriver and the Chrome browser.You can get ChromeDriver from here.
Starting the webdriver and the Firefox browser.You can get GeckoDriver from here.
Starting the webdriver and the Internet Explorer browser.You can get IEDriverServer from here.
Starting the webdriver and the Safari browser.Nothing to download. The SafariDriver is integrated in Safari.
3. Open a website
4. Find an elementLet's try to find this element:
Find element by ID
Find element by Name
Find element by Class Name
Find element by Tag Name
Find element by Link TextWorks only for anchor elements.
Find element by Partial Link TextWorks only for anchor elements.
Find element by CSS SelectorYou can extract the CSS Selector from the browser. Or you can write your own by using an attribute from the element:
For our element, a custom CSS Selector would be:
Find element by XPathYou can extract the XPath from the browser. Or you can write your own by using an attribute from the element:
For our element, a custom XPath would be: You can read more about that here.
5. Click on an element
6. Write text inside an elementWorks only for inputs and text areas.
7. Select an optionWorks only for select elements.
Let's select Canada. 🇨🇦 You can use the visible text:
You can use the value:
You can also use the index:
8. Take a screenshot
9. Upload a fileThis works by using the send_keys method to write the local path of the file in the input type="file" element. Let's use this example:
You can read more about uploading files in a test here. 10. Execute JavaScriptIn some cases, you might need to execute some JavaScript code. This works exactly like you would execute it in your browser console.
11. Switch to iframe
12. Switch to the next tabYou have to store the handle of your current tab in a global variable. If you have only one tab open, the handle is 0.
13. Switch to the previous tab
14. Close tab15. Close alert
16. Refresh17. Hover
18. Right Click
19. Click with offsetIn order to precisely click on a certain position in a canvas element, you have to provide the offset. The offset represents the number of pixels to the right and down, starting from the top left corner of your canvas element.
20. Press Key
21. Drag and drop
22. Get Page Source
23. Get Cookies
24. Delete Cookies
25. Get first element from list
26. Configure Page Load Timeout
27. Configure Element Load Timeout
28. Set window size
29. Change the user agent string
30. Simulate webcam and microphone
31. Add Chrome Extension
32. Emulate mobile device
Browser Details
Maximize and Minimize
Switch to Frame & Window
Back, Forward & Refresh
Cookies
Finding Elements |