Skip to content

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.

# executing javascript code and collecting the return.
result = bot.execute_javascript(code="return 1+1;")
print(result)
// executing javascript code and collecting the return.
Object result = executeJavascript("return 1+1;");
System.out.println(result);

Getting the page title

To collect the page title, use the method below.

print(f'Page Title: {bot.page_title()}')
System.out.println("Page Title: " + pageTitle());

Getting HTML code from the page

If you need to collect HTML code from the page, use the method below.

# collecting html.
page = page_source()

# showing the collected html.
print(html)
import org.jsoup.nodes.Document;

// collecting html.
Document page = pageSource();

// showing the collected html.
System.out.printf(page.html());