本文整理汇总了Java中org.openqa.selenium.WebDriver.TargetLocator类的典型用法代码示例。如果您正苦于以下问题:Java TargetLocator类的具体用法?Java TargetLocator怎么用?Java TargetLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TargetLocator类属于org.openqa.selenium.WebDriver包,在下文中一共展示了TargetLocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HiddenHtmlPrompt
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
public HiddenHtmlPrompt( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
示例2: windowTitleWithPercentage
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
public void windowTitleWithPercentage() throws Throwable {
driver = new JavaDriver();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame.setTitle("My %Dialog%");
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
WebElement element1 = driver.findElement(By.name("click-me"));
String id1 = ((RemoteWebElement) element1).getId();
// driver.switchTo().window("My %25Dialog%25");
TargetLocator switchTo = driver.switchTo();
switchTo.window("My %Dialog%");
WebElement element2 = driver.findElement(By.name("click-me"));
String id2 = ((RemoteWebElement) element2).getId();
AssertJUnit.assertEquals(id1, id2);
}
示例3: HiddenHtmlAlert
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
public HiddenHtmlAlert( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
示例4: HiddenHtmlConfirm
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
public HiddenHtmlConfirm( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
示例5: onCommand
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Object onCommand(Context context) {
TargetLocator tl = getSession().switchTo();
if (index >= 0) {
tl.frame(index);
}
if (StringUtils.isNotBlank(name)) {
tl.frame(name);
}
if (top != null && top) {
tl.defaultContent();
}
return null;
}
示例6: testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenIndex
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenIndex() {
TargetLocator locator = mockTargetLocator();
NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
doThrow(exception).when(locator).frame(INDEX);
try {
cut.setFocusOnFrame(INDEX);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
示例7: testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenNameOrId
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenNameOrId() {
TargetLocator locator = mockTargetLocator();
NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
doThrow(exception).when(locator).frame(NAME_OR_ID);
try {
cut.setFocusOnFrame(NAME_OR_ID);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
示例8: testExceptionHandlingInCaseAWindowIsNotFoundForTheGivenNameOrHandle
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test(expected = NoSuchWindowException.class)
public void testExceptionHandlingInCaseAWindowIsNotFoundForTheGivenNameOrHandle() {
TargetLocator locator = mockTargetLocator();
NoSuchWindowException exception = createSeleniumExceptionOfClass(NoSuchWindowException.class);
doThrow(exception).when(locator).window(NAME_OR_HANDLE);
try {
cut.setFocusOnWindow(NAME_OR_HANDLE);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
示例9: switchTo
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
// This is ugly :(
if (targetLocator instanceof CachingTargetLocator) {
return ((CachingTargetLocator) targetLocator).frame(parent, index);
}
parent.switchTo(targetLocator);
return targetLocator.frame(index);
}
示例10: findWindow
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
private String findWindow(TargetLocator targetLocator) {
for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
Browser forWindowHandle = By.id(windowHandle).find(Browser.class, parentContext);
view.setContext(forWindowHandle);
if (view.isLoaded()) {
return windowHandle;
}
}
throw new NoSuchWindowException("No window in driver found which has " + view + " "
+ "currently loaded.");
}
示例11: switchTo
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
public TargetLocator switchTo() {
return driver.switchTo();
}
示例12: testThatSwitchingToFrameWithIndexInvokesCorrectLocatorMethod
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test
public void testThatSwitchingToFrameWithIndexInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnFrame(INDEX);
verify(locator).frame(INDEX);
}
示例13: testThatSwitchingToFrameWithNameOrIdInvokesCorrectLocatorMethod
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test
public void testThatSwitchingToFrameWithNameOrIdInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnFrame(NAME_OR_ID);
verify(locator).frame(NAME_OR_ID);
}
示例14: testThatSwitchingToWindowWithNameOrHanldeInvokesCorrectLocatorMethod
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test
public void testThatSwitchingToWindowWithNameOrHanldeInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnWindow(NAME_OR_HANDLE);
verify(locator).window(NAME_OR_HANDLE);
}
示例15: testThatSwitchingToDefaultContentInvokesCorrectLocatorMethod
import org.openqa.selenium.WebDriver.TargetLocator; //导入依赖的package包/类
@Test
public void testThatSwitchingToDefaultContentInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnDefaultContent();
verify(locator).defaultContent();
}