本文整理汇总了TypeScript中selenium-webdriver.By.className方法的典型用法代码示例。如果您正苦于以下问题:TypeScript By.className方法的具体用法?TypeScript By.className怎么用?TypeScript By.className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium-webdriver.By
的用法示例。
在下文中一共展示了By.className方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: TestBy
function TestBy() {
let driver: webdriver.WebDriver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
let locator: webdriver.By = new webdriver.By('class name', 'class');
let str: string = locator.toString();
locator = webdriver.By.className('class');
locator = webdriver.By.css('css');
locator = webdriver.By.id('id');
locator = webdriver.By.linkText('link');
locator = webdriver.By.name('name');
locator = webdriver.By.partialLinkText('text');
locator = webdriver.By.tagName('tag');
locator = webdriver.By.xpath('xpath');
// Can import 'By' without import declarations
let By = webdriver.By;
let locatorHash: webdriver.ByHash;
locatorHash = { className: 'class' };
locatorHash = { css: 'css' };
locatorHash = { id: 'id' };
locatorHash = { linkText: 'link' };
locatorHash = { name: 'name' };
locatorHash = { partialLinkText: 'text' };
locatorHash = { tagName: 'tag' };
locatorHash = { xpath: 'xpath' };
webdriver.By.js('script', 1, 2, 3)(driver).then((abc: number) => {});
}
示例2: TestUntilModule
function TestUntilModule() {
let driver: webdriver.WebDriver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
let conditionB: webdriver.Condition<boolean> = new webdriver.Condition<boolean>('message', (driver: webdriver.WebDriver) => true);
let conditionBBase: webdriver.Condition<boolean> = conditionB;
let conditionWebElement: webdriver.WebElementCondition;
let conditionWebElements: webdriver.Condition<webdriver.WebElement[]>;
conditionB = webdriver.until.ableToSwitchToFrame(5);
let conditionAlert: webdriver.Condition<webdriver.Alert> = webdriver.until.alertIsPresent();
let el: webdriver.WebElement = driver.findElement(webdriver.By.id('id'));
conditionB = webdriver.until.stalenessOf(el);
conditionB = webdriver.until.titleContains('text');
conditionB = webdriver.until.titleIs('text');
conditionB = webdriver.until.titleMatches(/text/);
conditionB = webdriver.until.urlContains('text');
conditionB = webdriver.until.urlIs('text');
conditionB = webdriver.until.urlMatches(/text/);
conditionWebElement = webdriver.until.elementIsDisabled(el);
conditionWebElement = webdriver.until.elementIsEnabled(el);
conditionWebElement = webdriver.until.elementIsNotSelected(el);
conditionWebElement = webdriver.until.elementIsNotVisible(el);
conditionWebElement = webdriver.until.elementIsSelected(el);
conditionWebElement = webdriver.until.elementIsVisible(el);
conditionWebElement = webdriver.until.elementLocated(webdriver.By.id('id'));
conditionWebElement = webdriver.until.elementTextContains(el, 'text');
conditionWebElement = webdriver.until.elementTextIs(el, 'text');
conditionWebElement = webdriver.until.elementTextMatches(el, /text/);
conditionWebElements = webdriver.until.elementsLocated(webdriver.By.className('class'));
}
示例3: TestWebElement
function TestWebElement() {
var driver: webdriver.WebDriver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
var promise: webdriver.promise.Promise<string>;
var element: webdriver.WebElement;
element = new webdriver.WebElement(driver, 'elementId');
element = new webdriver.WebElement(driver, promise);
var voidPromise: webdriver.promise.Promise<void>;
var stringPromise: webdriver.promise.Promise<string>;
var booleanPromise: webdriver.promise.Promise<boolean>;
voidPromise = element.clear();
voidPromise = element.click();
element = element.findElement(webdriver.By.id('ABC'));
element.findElements(webdriver.By.className('ABC')).then(function (elements: webdriver.WebElement[]) { });
booleanPromise = element.isElementPresent(webdriver.By.className('ABC'));
stringPromise = element.getAttribute('class');
stringPromise = element.getCssValue('display');
driver = element.getDriver();
stringPromise = element.getInnerHtml();
element.getLocation().then(function (location: webdriver.ILocation) { });
stringPromise = element.getOuterHtml();
element.getSize().then(function (size: webdriver.ISize) { });
stringPromise = element.getTagName();
stringPromise = element.getText();
booleanPromise = element.isDisplayed();
booleanPromise = element.isEnabled();
booleanPromise = element.isSelected();
voidPromise = element.sendKeys('A', 'B', 'C');
voidPromise = element.sendKeys(1, 2, 3);
voidPromise = element.sendKeys(webdriver.Key.BACK_SPACE);
voidPromise = element.sendKeys(stringPromise, stringPromise, stringPromise);
voidPromise = element.sendKeys('A', 1, webdriver.Key.BACK_SPACE, stringPromise);
voidPromise = element.submit();
element.getId().then(function (id: string) { });
element.getRawId().then(function (id: string) { });
element.serialize().then(function (id: webdriver.IWebElementId) { });
booleanPromise = webdriver.WebElement.equals(element, new webdriver.WebElement(driver, 'elementId'));
}
示例4: hideTests
async hideTests() {
const testElems = await this.ctx.driver.findElements(By.className('test-elem'))
if (testElems.length > 0) {
await this.ctx.driver.executeScript((elements: HTMLElement[]) => {
elements.forEach(e => e.style.setProperty('display', 'none'))
}, testElems)
}
}
示例5: hideServerUuid
async hideServerUuid() {
try {
const serverUuid = await this.ctx.driver.findElement(By.className('rundeck-server-uuid'))
if (serverUuid)
await this.ctx.driver.executeScript((element: HTMLElement) => {
element.parentElement.parentElement.parentElement.style.setProperty('display', 'none')
}, serverUuid)
} catch{}
}
示例6: correctTitle
@AsyncTest("page title is Home")
public async correctTitle() {
// get the wiki title
const title = await this._driver
.findElement(By.className("gh-header-title"))
.getText();
// check it contains what we'd expect
Expect(title).toBe("Home");
}
示例7: findExtensionElement
async function findExtensionElement(driver: TypedWebdriver, capabilities: BrowserstackCapabilities) {
const version = getVersion(capabilities);
if (version < 36) {
console.error('Chrome extension testing before chrome 36 won\'t work,'
+ ' please try a higher chrome version or remove the --test-extension flag');
process.exit(1);
throw new Error('Chrome extension testing before chrome 36 won\'t work,'
+ ' please try a higher chrome version or remove the --test-extension flag');
} else if (version < 61) {
await driver.get('chrome://extensions-frame/frame');
} else {
await driver.get('chrome://extensions');
}
if (version < 66) {
const extensions = await driver.findElements(
webdriver.By.className('extension-list-item-wrapper'));
for (const extension of extensions) {
const title = await extension.findElement(
webdriver.By.className('extension-title'));
if ((await title.getText()).indexOf('Custom Right-Click Menu') > -1) {
return extension;
}
}
return null;
} else {
const extensions = await findElement(webdriver.By.tagName('extensions-manager'))
.findElement(webdriver.By.tagName('extensions-item-list'))
.findElements(webdriver.By.tagName('extensions-item'));
for (const extension of extensions) {
const title = await extension.findElement(webdriver.By.id('name'));
if ((await title.getText()).indexOf('Custom Right-Click Menu') > -1) {
await extension.findElement(webdriver.By.id('detailsButton')).click();
await wait(1000);
return driver;
}
}
return null;
}
}
示例8: it
it('should be possible to click the install link', async function() {
this.timeout(20000);
this.slow(15000);
const button = await findElement(webdriver.By.id('install_script'))
.findElement(webdriver.By.tagName('a'));
title = await findElement(webdriver.By.className('title'))
.getText();
assert.exists(button, 'Install link exists');
href = await button.getProperty('href') as string;
const isUserScript = href.indexOf('.user.js') > -1;
assert.isTrue(isUserScript, 'button leads to userscript');
});
示例9: openOptionsPage
export async function openOptionsPage(driver: TypedWebdriver, capabilities: BrowserstackCapabilities) {
const version = getVersion(capabilities);
await wait(500);
const extensionElement = await findExtensionElement(driver, capabilities);
if (!extensionElement) {
console.error('Failed to find extension options page');
process.exit(1);
return;
}
if (version < 66) {
await extensionElement
.findElement(webdriver.By.className('options-link'))
.click();
const currentTab = await driver.getWindowHandle();
const tabs = await driver.getAllWindowHandles();
const nonCurrentTabs = tabs.filter((tab) => {
return tab !== currentTab;
});
//Close the curent tab
await driver.close();
//Switch to next tab
await driver.switchTo().window(nonCurrentTabs[0]);
return;
} else {
await findElement(webdriver.By.tagName('extensions-manager'))
.findElement(webdriver.By.tagName('extensions-detail-view'))
.findElement(webdriver.By.id('extensions-options'))
.click();
const currentTab = await driver.getWindowHandle();
const tabs = await driver.getAllWindowHandles();
const nonCurrentTabs = tabs.filter((tab) => {
return tab !== currentTab;
});
//Close the curent tab
await driver.close();
//Switch to next tab
await driver.switchTo().window(nonCurrentTabs[0]);
return;
}
}
示例10: getExtensionURLPrefix
export async function getExtensionURLPrefix(driver: TypedWebdriver, capabilities: BrowserstackCapabilities) {
const version = getVersion(capabilities);
const extensionElement = await findExtensionElement(driver, capabilities);
if (!extensionElement) {
console.error('Failed to find extension options page');
process.exit(1);
return null;
}
if (version < 66) {
const href = await extensionElement
.findElement(webdriver.By.className('options-link'))
.getAttribute('href');
return href.split('/html/options.html')[0];
} else {
return `chrome-extension://${await driver.executeScript(inlineFn(() => {
return location.href.split('?id=')[1];
}))}`;
}
}