Find Elements on a Webpage
- Integrated Circuits - - An Online Book - |
||||||||
Integrated Circuits http://www.globalsino.com/ICs/ | ||||||||
Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix | ||||||||
================================================================================= Steps to find elements on a webpage: i) Find the selector or locator information for those elements of interest, for instance, whith " Inspect" function on Chrome such as page4491. ii) Information can be used as elements are: iii) Tell Selenium how to find a particular element or set of elements on a web page programmatically and simulate user actions on these elements by passing the information which is found in the step above. iii.a) find_element(By.ID, ""). This returns all the elements that have the same ID attribute values. Example A: Use the code iii.b) find_element(By.XPATH, ""). Example A: Use the code Example B: Use the code Example C: Example D: (page4491) Example E: (page4491) Upload files by using Selenium (always use "input" for "send_key"): Example F: (page4491) Upload files by using Selenium (always use "input" for "send_key"): Example G : (page4491) Upload files with full XPATH when there are "multiple id":
iii.c) Find element(s) by their HTML tag name. find_element(By.TAG_NAME, ""). This is not a reliable way since this only selects the first tag in the webpage. However, there can be many tags with the same tage name. Code: ser = Service(r"C:\usr\local\bin\chromedriver.exe") driver.get("https://secure.yatra.com/social/common/yatra/signin.htm") iii.d) find_element(By.CLASS_NAME, ""). Code: ser = Service(r"C:\usr\local\bin\chromedriver.exe") driver.get("https://secure.yatra.com/social/common/yatra/signin.htm") iii.e) find_element(By.LINK_TEXT, ""). Code: iii.f) Partial Link Text by using the text which is not dynamic. find_element(By.PARTIAL_LINK_TEXT, ""). Code: iii.g) CSS.SELECTOR. find_element(By.CSS.SELECTOR, ""). Code: ============================================
|
||||||||
================================================================================= | ||||||||
|
||||||||