![]() ![]() Now, the fifth line of code is what we use to open our victim’s chatbox. driver.find_element_by_css_selector("span").click() From there, you can see its id, if it has one, its class etc., and you can right click on that line of code to find the elements’ XPath, selector etc.įor the purpose of this tutorial, all of this is unnecessary, as I’ve already found the required information, and at the time of writing this post, these paths work just fine. Keep going deeper and deeper into the code until you find a line that highlights just the element you want to click. You’ll notice you can expand that line of code. At first, it will seem like everything is highlighted. Then, hover over each line of code, which will highlight its corresponding element on the page. First, switch the tab on top to “Elements” if that’s not already selected. If you opened the console by hitting the shortcut keys, you’ll need to manually find your element. The shortcut keys may vary from browser to browser, but it’s a short web search away. How do we do that? Visit the page, right click on the element that you want to single out, and hit “inspect element” (it likely won’t work for WhatsApp Web, as a right click over there opens their custom context menu, not the standard one, in which case…), alternatively hit Ctrl Shift i (Windows) or Command Option i (Mac). We need a way of uniquely identifying each element, so we can tell our code to look for it. Next up, we need to start looking for identifiers for elements on our web page. Make sure to start your links with “http” (and “https” where available). The fourth line of code simply starts a new instance of our browser through our driver. There’s no need to decrease the timer however, because the moment the element is found, the code will proceed. You can increase this timer if you have an even slower internet connection. With the third line of code, we’re telling our driver to look for an element for at least 15 seconds before reporting it rogue to us. The page could still be loading, for example. ![]() But an element can be missing from a page for many reasons. ![]() See, when we ask Selenium to get an element from a page for us, if the element is not found on the page, an exception is thrown, which stops your code in its tracks if you haven’t handled it well. ![]() The third line tells our driver to implicitly wait for 15 seconds. Once you find the webdriver and download it, you’ll want to copy its path and paste it over where it currently says “C:\\webdrivers\\chromedriver.exe” (Note the double backslashes to escape a single backslash) 3. For example, you’ll find the chrome webdriver here. This driver is a file that contains instructions that let you interact with the browser, specifically Chrome browser in this case, and you can get it from anywhere on the internet. The second line is us specifying where we’re getting our “driver” from. driver = webdriver.Chrome('C:\\webdrivers\\chromedriver.exe') We can’t use a part of Selenium unless we import them, right? Here, we’re importing “webdriver”, which is something that allows your code to interact with a browser like a human does. A weapon of mass communication.ĭon’t let the disgusting structure of the code intimidate you, let’s walk through it line by line. Nothing says aggressive like 100 messages a minute.Īlright then, here’s your code for the day: from selenium import webdriver driver = webdriver.Chrome('C:\\webdrivers\\chromedriver.exe') driver.implicitly_wait(15) driver.get(' ') driver.find_element_by_css_selector("span").click() inputString = input("Enter message to send: ") while(True): driver.find_element_by_xpath('//*[ driver.find_element_by_xpath('//*[ yes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |