UNPKG

selenium-webdriver-mcp

Version:
80 lines 2.57 kB
import { until } from 'selenium-webdriver'; import { LocatorFactory } from '../utils/locators.js'; export class ElementService { driver; constructor(driver) { this.driver = driver; } async findElement(params) { const locator = LocatorFactory.createLocator(params.by, params.value); return this.driver.wait(until.elementLocated(locator), params.timeout || 15000); } async findElements(params) { const locator = LocatorFactory.createLocator(params.by, params.value); await this.driver.wait(until.elementsLocated(locator), params.timeout || 15000); return this.driver.findElements(locator); } async getElementText(params) { const element = await this.findElement(params); return element.getText(); } async clickElement(params) { const element = await this.findElement(params); await element.click(); } async sendKeysToElement(params) { const element = await this.findElement(params); await element.clear(); await element.sendKeys(params.text); } async getElementAttribute(params) { const element = await this.findElement(params); return element.getAttribute(params.attribute); } async clearElement(params) { const element = await this.findElement(params); await element.clear(); } async uploadFile(params) { const element = await this.findElement(params); await element.sendKeys(params.filePath); } async isElementDisplayed(params) { try { const element = await this.findElement(params); return element.isDisplayed(); } catch { return false; } } async isElementEnabled(params) { try { const element = await this.findElement(params); return element.isEnabled(); } catch { return false; } } async isElementSelected(params) { try { const element = await this.findElement(params); return element.isSelected(); } catch { return false; } } async switchToFrame(params) { const element = await this.findElement(params); await this.driver.switchTo().frame(element); } async switchToDefaultContent() { await this.driver.switchTo().defaultContent(); } async switchToParentFrame() { await this.driver.switchTo().parentFrame(); } } //# sourceMappingURL=elementService.js.map