Saved Text Snippet
Saved Text
# Exam Automation: AI Auto-Solver Script Generator
This guide explains how to generate an automated JavaScript snippet where the AI (like Gemini) not only writes the script but also **solves the exam questions for you**.
## Workflow
Instead of providing the correct answers yourself, you will ask the AI to solve the questions extracted from the XML file.
You only need to provide the **XML output** for the exam section.
The AI will:
1. Read and understand the questions from the XML.
2. Solve the questions to find the correct answers.
3. Map its solved answers to their respective hidden `VALUE` codes.
4. Generate a ready-to-run JavaScript script that you can paste into your browser's Developer Console.
## Prompt Template for Gemini
Copy and paste the text below into Gemini, replacing the placeholder with your actual XML data:
---
**Prompt:**
I have an online exam system where the frontend uses radio buttons for multiple-choice questions. The values for these radio buttons are hidden in an XML file.
Below, I am providing the XML structure of an exam section containing multiple questions.
**Task:**
1. Act as an expert in the subject matter and **solve each question** found in the XML to determine the correct answer.
2. Match your solved correct answer to the corresponding `<ANSWER>` tag in the XML.
3. Extract the `VALUE` attribute for each correct answer you identified.
4. Plug that ordered list of `VALUE` attributes into the `answers` array in the JavaScript template below.
5. (Optional) Provide a brief explanation for your answers so I can verify them.
6. Return the finalized, ready-to-run JavaScript code.
**XML Data:**
\```xml
[PASTE YOUR XML HERE]
\```
**JavaScript Template:**
\```javascript
(function() {
// These are the exact VALUE attributes from the XML for the correct answers calculated by the AI
const answers = [
// AI TO INSERT COMMA-SEPARATED VALUES HERE
];
let currentIndex = 0;
// The exam uses two frames: 'a' for logic/state, and 'c' for the visual UI
const frameA = window.frames['a'];
const frameC = window.frames['c'];
if (!frameA || !frameC) {
console.error("Error: Could not find the exam frames. Make sure you are running this on the main index.php page.");
return;
}
// Force jump to the first question (index 0) to ensure we start from the beginning
frameA.jump(0);
function processNextQuestion() {
if (currentIndex >= answers.length) {
console.log("%cā
All questions have been answered and saved successfully!", "color: green; font-size: 16px; font-weight: bold;");
return;
}
console.log(`Answering Question ${currentIndex + 1}...`);
// Wait 0.5s for the UI of the current question to fully render
setTimeout(() => {
const radios = frameC.document.getElementsByName('ans');
const targetValue = answers[currentIndex].toString();
let found = false;
// 1. Select the correct radio button
for (let i = 0; i < radios.length; i++) {
if (radios[i].value === targetValue) {
radios[i].checked = true;
found = true;
break;
}
}
if (found) {
// 2. Trigger the native Save & Next function
// This automatically fires the AJAX request to updateDB.php and renders the next question
frameA.next('SAVE');
} else {
console.error(`ā Could not find radio button with value ${targetValue} for Question ${currentIndex + 1}`);
}
// Move our index to the next one
currentIndex++;
// Wait 2.5 seconds before doing the next question
// This ensures we don't overwhelm the server and wait for the AJAX database save to complete securely
setTimeout(processNextQuestion, 2500);
}, 500);
}
// Give it a brief moment to finish the initial jump(0), then start processing
console.log("%cš Starting automatic answer submission...", "color: blue; font-size: 14px;");
setTimeout(processNextQuestion, 1000);
})();
\```
---
Sponsored Content
Exclusive offer