Skip to content

Commit 6f53603

Browse files
committed
Browser add explaination and example
1 parent 0c3f2a0 commit 6f53603

17 files changed

+433
-16
lines changed

docs/api/browser/click.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ data:
2222
<CBParameters/>
2323

2424
### Examples
25+
2526
```js
26-
var a=1
27-
```
27+
// Using Codebolt's browser API, you can interact with elements on a web page.
28+
// For example, let's say there's a button with the ID "test" on the page.
29+
// You can use Codebolt's browser API to click on this button.
30+
31+
32+
// First, let's imagine there's a button with the ID "test" on the web page.
33+
// <button id="test">Click me</button>
34+
35+
// Now, you want to use Codebolt's browser API to click on this button.
36+
37+
// The syntax for clicking an element with a specific ID using Codebolt's browser API is:
38+
// await codebolt.browser.click("elementSelector")
39+
40+
// In this case, the element selector is "#test" because we are targeting an element with the ID "test".
41+
42+
// Putting it all together:
43+
codebolt.browser.click("#test");
44+
45+
```
46+
47+
### Explaination
48+
49+
[Browser](../../concepts/browser) Click function is used to click on the browser by selecting specific elementId.
50+
51+
A browser is a used to access and display web pages on the internet. When a browser is open, users can interact with various elements on web pages, such as buttons, links, forms, and images.
52+
53+
One common action in web development and automation is clicking on specific elements within a web page. This action is typically performed by selecting the element using its unique identifier, often referred to as the element ID, and then triggering a click event on that element.

docs/api/browser/close.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ data:
1616
<CBBaseInfo/>
1717
<CBParameters/>
1818

19+
### Examples
20+
```js
21+
// Open the browser and navigate to a specific URL
22+
codebolt.browser.goToPage(url);
23+
24+
// Perform tests on the web page
25+
// (Assume you have performed all necessary tests)
26+
27+
// Close the current page
28+
codebolt.browser.close();
29+
30+
```
31+
### Explaination
32+
33+
Navigation: The script first opens a browser window/tab and navigates to the specified URL using codebolt.browser.goToPage(url). In this example, it navigates to "https://example.com".
34+
35+
Testing: Once on the web page, the script performs various tests to validate the functionality of the application.
36+
37+
Closing the Page: After completing the tests on the current page, the codebolt.browser.close() function is used to close the current page/tab. This action is useful for cleaning up after testing is complete and for ensuring that the browser environment is left in a desired state.
1938

2039

2140

docs/api/browser/enter.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,30 @@ data:
1616
link: enter.md
1717
---
1818
<CBBaseInfo/>
19-
<CBParameters/>
19+
<CBParameters/>
20+
21+
### Examples
22+
23+
```js
24+
25+
// Navigate to the sign-in page
26+
await codebolt.browser.goToPage("https://example.com/signin");
27+
28+
// Fill in the username field
29+
await codebolt.browser.type("#username", "your_username");
30+
31+
// Fill in the password field
32+
await codebolt.browser.type("#password", "your_password");
33+
34+
// Simulate pressing the Enter key to submit the form
35+
await codebolt.browser.enter();
36+
37+
```
38+
39+
### Explanation:
40+
41+
Navigation: The script navigates to the sign-in page of the website.
42+
43+
Entering Data: Using codebolt.browser.type(), the script fills in the username and password fields with the appropriate credentials.
44+
45+
Simulating Enter Key Press: Instead of clicking a submit button, the script uses codebolt.browser.enter() to simulate pressing the Enter key. This action triggers the default submission behavior of the form, submitting the entered username and password for authentication.

docs/api/browser/extractText.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,26 @@ data:
1414
link: extractText.md
1515
---
1616
<CBBaseInfo/>
17-
<CBParameters/>
17+
<CBParameters/>
18+
19+
### Examples:
20+
21+
```js
22+
// Navigate to the news website
23+
await codebolt.browser.goToPage("https://example-news.com");
24+
25+
// Extract all text from the current page
26+
const pageText = await codebolt.browser.extractText();
27+
28+
// Log the extracted text to the console (or process it as needed)
29+
console.log(pageText);
30+
31+
```
32+
33+
### Explaination:
34+
35+
Navigation: The script starts by navigating to the news website's homepage using codebolt.browser.goToPage("https://example-news.com").
36+
37+
Text Extraction: Once the page has loaded, the script uses codebolt.browser.extractText() to extract all the text content from the current page. This function captures all textual information present on the web page, including headings, paragraphs, and any other text elements.
38+
39+
Processing the Extracted Text: The extracted text is stored in the variable pageText. In this example, the script simply logs the extracted text to the console using console.log(pageText). In a real-world scenario, you might further process this text to analyze news headlines, summarize content, or extract specific information.

docs/api/browser/getContent.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,30 @@ data:
1414
link: getContent.md
1515
---
1616
<CBBaseInfo/>
17-
<CBParameters/>
17+
<CBParameters/>
18+
19+
### Examples:
20+
21+
```js
22+
23+
// Navigate to the blog page
24+
await codebolt.browser.goToPage("https://example-blog.com/article")
25+
26+
// Retrieve the HTML content of the current page
27+
const pageContent = await codebolt.browser.getContent()
28+
29+
// Log the retrieved content to the console (or save it as needed)
30+
console.log(pageContent)
31+
32+
```
33+
34+
### Explanation:
35+
The codebolt.browser.getContent() function is used to retrieve the entire HTML content of the current web page. This function is particularly useful in web scraping, data extraction, and automated testing scenarios where you need to capture the full structure and content of a web page for further processing or analysis.
36+
37+
### Explaination of the code:
38+
39+
Navigation: The script begins by navigating to the specific blog page using codebolt.browser.goToPage("https://example-blog.com/article").
40+
41+
Content Retrieval: Once the page has fully loaded, the script uses codebolt.browser.getContent() to retrieve the complete HTML content of the current page. This includes all HTML tags, embedded styles, scripts, and textual content.
42+
43+
Processing the Retrieved Content: The retrieved HTML content is stored in the variable pageContent. In this example, the script logs the HTML content to the console using console.log(pageContent). In a real-world scenario, you might save this content to a file or a database for later analysis or offline access.

docs/api/browser/getHTML.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,32 @@ data:
1616
link: getHTML.md
1717
---
1818
<CBBaseInfo/>
19-
<CBParameters/>
19+
<CBParameters/>
20+
21+
### Examples :
22+
23+
```js
24+
25+
// Navigate to the product page
26+
await codebolt.browser.goToPage("https://example-ecommerce.com/product/12345")
27+
28+
// Retrieve the HTML content of the current page
29+
const htmlContent = await codebolt.browser.getHTML()
30+
31+
// Log the retrieved HTML content to the console (or save it as needed)
32+
console.log(htmlContent)
33+
34+
```
35+
36+
### Explaination:
37+
38+
The codebolt.browser.getHTML() function is used to retrieve the HTML content of the current web page. This function is particularly useful for web scraping, data extraction, and automated testing scenarios where you need to capture the entire HTML structure and content of a web page for further analysis or processing.
39+
40+
41+
### Explaination of the code:
42+
43+
Navigation: The script begins by navigating to the specific blog page using codebolt.browser.goToPage("https://example-blog.com/article").
44+
45+
HTML Content Retrieval: Once the page has fully loaded, the script uses codebolt.browser.getHTML() to retrieve the complete HTML content of the current page. The function returns a promise that resolves to the HTML content, which includes all HTML tags, embedded styles, scripts, and textual content.
46+
47+
Processing the Retrieved HTML: The retrieved HTML content is stored in the variable htmlContent. In this example, the script logs the HTML content to the console using console.log(htmlContent). Additionally, the example demonstrates how to save the HTML content to a file using Node.js's file system module (fs), which writes the HTML content to a file named product-page.html.

docs/api/browser/getMarkdown.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,39 @@ data:
1616
link: getMarkdown.md
1717
---
1818
<CBBaseInfo/>
19-
<CBParameters/>
19+
<CBParameters/>
20+
21+
### Examples:
22+
23+
```js
24+
25+
// Navigate to the blog post page
26+
await codebolt.browser.goToPage("https://example-blog.com/post/12345");
27+
28+
// Retrieve the Markdown content of the current page
29+
const markdownContent = await codebolt.browser.getMarkdown();
30+
31+
// Log the retrieved Markdown content to the console (or save it as needed)
32+
console.log(markdownContent);
33+
34+
```
35+
36+
37+
### Explanation:
38+
39+
The codebolt.browser.getMarkdown() function is used to retrieve the Markdown representation of the content on the current web page. This function is particularly useful for converting HTML content into a more readable and editable Markdown format, which is widely used in documentation, blogging, and content management systems.
40+
41+
42+
### Explanation of the Code
43+
44+
Navigation: The script starts by navigating to a specific blog post page using codebolt.browser.goToPage("https://example-blog.com/post/12345").
45+
46+
47+
Markdown Content Retrieval: Once the page has fully loaded, the script uses codebolt.browser.getMarkdown() to retrieve the content of the current page in Markdown format. This function converts the HTML content into Markdown, capturing the structure and text in a more readable format.
48+
49+
50+
Processing the Retrieved Markdown: The retrieved Markdown content is stored in the variable markdownContent. In this example, the script logs the Markdown content to the console using console.log(markdownContent). Additionally, the example demonstrates how to save the Markdown content to a file using Node.js's file system module (fs), which writes the content to a file named post.md.
51+
52+
53+
54+

docs/api/browser/getPDF.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,34 @@ data:
1414
link: getPDF.md
1515
---
1616
<CBBaseInfo/>
17-
<CBParameters/>
17+
<CBParameters/>
18+
19+
### Examples:
20+
21+
```js
22+
23+
// Navigate to the news article page
24+
await codebolt.browser.goToPage("https://example-news.com/article/12345");
25+
26+
// Retrieve the PDF content of the current page
27+
const pdfContent = await codebolt.browser.getPDF();
28+
29+
// Log a message to indicate the PDF has been retrieved (optional)
30+
console.log("PDF content retrieved successfully");
31+
32+
```
33+
34+
35+
### Explanation
36+
37+
The codebolt.browser.getPDF() function is used to retrieve a PDF representation of the current web page. This function is particularly useful for generating PDF versions of web pages for documentation, archiving, or sharing purposes. It captures the visual layout and content of the web page as a PDF file.
38+
39+
40+
41+
### Explanation of the Code
42+
43+
Navigation: The script starts by navigating to a specific news article page using codebolt.browser.goToPage("https://example-news.com/article/12345").
44+
45+
PDF Content Retrieval: Once the page has fully loaded, the script uses codebolt.browser.getPDF() to retrieve the content of the current page as a PDF. This function captures the entire visual layout and content of the page, creating a PDF file that mirrors the web page's appearance.
46+
47+
Processing the Retrieved PDF: The retrieved PDF content is stored in the variable pdfContent. In this example, the script logs a message to the console to indicate that the PDF has been successfully retrieved.

docs/api/browser/getUrl.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,29 @@ data:
1616
link: getUrl.md
1717
---
1818
<CBBaseInfo/>
19-
<CBParameters/>
19+
<CBParameters/>
20+
21+
22+
### Examples:
23+
24+
```js
25+
26+
// Navigate to the home page
27+
await codebolt.browser.goToPage("https://example-website.com");
28+
29+
// Retrieve and log the current URL
30+
let currentUrl = await codebolt.browser.getUrl();
31+
console.log(`Current URL: ${currentUrl}`);
32+
33+
```
34+
35+
### Explanation
36+
37+
The codebolt.browser.getUrl() function is used to retrieve the URL of the current active page in the browser. This function is useful in web automation, testing, and navigation scenarios where you need to confirm or log the URL of the page that the browser is currently displaying.
38+
39+
40+
### Explanation of the Code
41+
Navigation to Home Page: The script begins by navigating to the home page of the website using codebolt.browser.goToPage("https://example-website.com").
42+
43+
Retrieving the Current URL: After the page has loaded, the script uses codebolt.browser.getUrl() to retrieve the current URL of the browser's active page. The retrieved URL is stored in the variable currentUrl.
44+

docs/api/browser/goToPage.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,22 @@ data:
1919
link: goToPage.md
2020
---
2121
<CBBaseInfo/>
22-
<CBParameters/>
22+
<CBParameters/>
23+
24+
### Examples
25+
26+
```js
27+
28+
//Navigate to a webpage using Codebolt's browser API
29+
await codebolt.browser.goToPage('https://docs.codebolt.ai/docs/api/browser/goToPage/')
30+
31+
32+
```
33+
34+
### Explanation
35+
36+
[browser](../../concepts/browser) The codebolt.browser.goToPage(url) function is used to navigate the browser to a new web page specified by the URL provided. When this function is called, the browser leaves the current page and loads the new page indicated by the URL.
37+
38+
39+
40+

docs/api/browser/newPage.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ data:
1414
link: newPage.md
1515
---
1616
<CBBaseInfo/>
17-
<CBParameters/>
17+
<CBParameters/>
18+
19+
### Examples:
20+
21+
```js
22+
// Open a new page in the browser
23+
await codebolt.browser.newPage();
24+
25+
```
26+
27+
### Explanation
28+
The codebolt.browser.newPage() function is used to open a new tab or window in the browser. This function is useful in web automation, testing, and multi-page navigation scenarios where you need to interact with multiple pages simultaneously.

docs/api/browser/pdfToText.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,19 @@ data:
1414
link: pdfToText.md
1515
---
1616
<CBBaseInfo/>
17-
<CBParameters/>
17+
<CBParameters/>
18+
19+
### Examples:
20+
21+
```js
22+
23+
// Navigate to the page containing the PDF document
24+
await codebolt.browser.goToPage("https://example.com/report.pdf");
25+
26+
// Convert the PDF content to text
27+
codebolt.browser.pdfToText();
28+
29+
```
30+
31+
### Explanation
32+
The codebolt.browser.pdfToText() function is used to convert the PDF content of the current page into text format. This function is particularly useful when dealing with PDF documents in web automation or data extraction scenarios where you need to extract textual information from PDF files.

0 commit comments

Comments
 (0)