Automate browser operations
Step 1: Analyze website
When automating, it is usually about entering text into specific fields or clicking certain buttons. These input fields must be located to later tell the browser in which input fields something should be entered. By right-clicking on the element and clicking "Inspect" in the context menu, the HTML view opens at the bottom of the browser and highlights the current element. You now locate the individual elements as follows:- Is an attribute
id="irgendwas"present, you locate the element with#irgendwas - Is an attribute
name="irgendwas"present, you locate the element with[name="irgendwas"] - If neither id nor name only the path through the surroundings of the element remains: All clues suitable for uniquely identifying the element serve this purpose, especially surrounding classes and the classes of the element. Example: We want to identify the input field in the p-environment
<p class="input-name"><input></p>is for example withp.input-name inputlocated - The W3C provides precise documentation of all selectors for locating elements at this link
Step 2: Ensure that jQuery is present
When in the Inspect Element view, there is a text line at the bottom that usually starts with a >>. This is where you enter JavaScript commands. Now, the jQuery library must still be loaded. You check this by typing "$" there and pressing ENTER. If "function()" appears as a response, jQuery is properly loaded. If "undefined" appears instead, we still need to load it. This is done by entering the following command and pressing ENTER: "script = document.createElement('script'); script.src = 'https://code.jquery.com/jquery-latest.min.js'; document.body.appendChild(script);". Subsequently, entering "$" should return a "function()".
Step 3: Automatically fill input fields
From Step 1, we have selected the selectors for the input fields. We now use these in a command:$('hier Selektor eintragen').val('hier Wert eintragen');
Example: $('#url').val('http://launix.de');
If you want more than just static text in the values, such as the first and last name of the Xing contact for whom you are sending the contact request, simply dive a bit deeper into JavaScript and jQuery. It is fundamentally quite simple once you have understood the basic mechanisms.
Step 4: trigger the click
From step 1, we identified the selector for the submit button. We will now trigger the click for this:$('hier Selektor eintragen').click();
Example: $('input[type="submit"]').click();