The easiest way to change the contents of an eBay / DOM page

Obviously, Selenium was not intended to change the DOM of browser pages, but sometimes I need to dynamically insert HTML elements.

In this case: I am using Firefox with the Selenium IDE to record auction listings on eBay, but I noticed that it does not cope with tight controls on the contents of the JScripted auction and does not record anything for these elements.

If I disable JavaScript for the ebay website, a much simpler version of the first auction entry page does not work (it does not have a hidden input element needed to confirm PayPal as a payment method).

So, my options at the moment are as follows: A) figure out how to interact with the unusual control element of the JScript HTML editor from Selenium, or b) insert new elements into the DOM.

Does anyone have any suggestions, preferably in C #, as I am automating this under a Windows console application? Selenium custom extensions will also be acceptable if someone has code.

+4
source share
1 answer

I have found one solution so far, so I decided to share it better for review / improvement.

Selenium allows you to extend your behavior using the user-extensions.js file .

For example, this creates a new insertHtml command in Selenium:

Selenium.prototype.doInsertHtml = function(locator, text){ var element = this.page().findElement(locator); var innerHTML = text + element.innerHTML; element.innerHTML = innerHTML; } 

To use the Selenium IDE, you simply include the extension file through the options menu of the IDE itself. The next time you run the IDE, it will automatically have new available commands (from the user extension file).

As the page address of the document changed and was reused, I copied the corresponding part below:

Selenium expansion

It can be quite simple to extend Selenium by adding your own actions, statements and locator strategies. This is done using javascript by adding methods to the prototype of the Selenium object and the prototype of the PageBot object. When launched, Selenium will automatically look at the methods on these prototypes, using name patterns to recognize which ones are actions, statements, and locators.

The following examples provide guidance on how Selenium can be expanded using javascript.

Actions

All doFoo methods on the Selenium prototype are added as actions. For each foo action, there is also the fooAndWait action registered. An action method can take up to 2 parameters, which will be passed in the second and third column values ​​in the test.

Example: add the action "typeRepeated" in Selenium, which twice enters the text in the text box.

 Selenium.prototype.doTypeRepeated = function(locator, text) { // All locator-strategies are automatically handled by "findElement" var element = this.page().findElement(locator); // Create the text to type var valueToType = text + text; // Replace the element text with the new text this.page().replaceText(element, valueToType); }; 
+1
source

Source: https://habr.com/ru/post/1399792/


All Articles