DOM¶
Use the methods below to manipulate, view information, or execute Javascript code in the DOM.
Searching for elements¶
Use the method below to collect one or several elements in the DOM.
Tip
If you can't access an element but it is on the page, make sure that it is not inside an iframe. If it is inside an iframe you need to go into the iframe and search inside. Click here for more information.
Parameter | Description |
---|---|
selector | the identifier that will be used to fetch the element. |
by | the type of selector |
Operations with the element
When the element is returned you can click on it or send a value to it
# Import for the By enum.
from botcity.web import By
# searching for an element by ID.
username_field = bot.find_element(selector='username', by=By.ID)
# clicking on the element.
username_field.click()
# sending a value to the element.
username_field.send_keys('my_username')
# searching for several elements that contain in their class name the value 'container.
divs = bot.find_elements(selector='container', by=By.CLASS_NAME)
print(len(divs))
// Import for the By enum.
import org.openqa.selenium.By;
// searching for an element by ID.
WebElement usernameField = findElement(By.id("username"));
// clicking on the element.
usernameField.click();
// sending a value to the element.
usernameField.sendKeys("my_username");
// searching for several elements that contain in their class name the value 'container.
List<WebElement> divs = findElements(By.className("container"));
System.out.println(divs.size());
Running Javascript¶
If you need to execute some logic that uses Javascript code, use the method below.
Getting the page title¶
To collect the page title, use the method below.
Getting HTML code from the page¶
If you need to collect HTML code from the page, use the method below.