There is a button in my application, which on click opens up a new window.
How can I verify the text in a new window?
I am using selenium web driver and Firefox browser.
You can do it with two ways.
1st use method
driver.switchTo().ActiveElement();
2nd
driver.switchTo().window("New Widnow tile")
Pass new window title as Parameter.
public String y[][];
public int size,i=0;
public void Get_Windows**`strong text`**()
{
Set<String> Handle = driver.getWindowHandles();
size= Handle.size();
String[] Temp = Handle.toArray(new String[size]);
String Tab_Id_Container[][]=new String[size][size];
while(size>0)
{
driver.switchTo().window(Temp[i]);
Tab_Id_Container[i][0]=driver.getTitle();
Tab_Id_Container[1][i]=driver.getWindowHandle();
System.out.println("Page name : "+Tab_Id_Container[i][0]);
System.out.println("Hex value : "+Tab_Id_Container[1][i]);
i++;
size--;
}
}
Try this one modify for your use
Related
I am currently working on a standalone app that can handle communication from a mobile and also utilizes VLC player to output a stream.
The way I do it is that output stream object is in the main window, but I receive requests via SignalR.
The request is fairly simple - it's just a string. The problem is I have no clue on how to pass the string from a SignalR hub back to the MediaPlayer object. How do I either get a string passed to an object outside or make a mediaplayer "persist" inside the hub? For now my code concerning it looks like this:
The hub:
[HubName("CommHub")]
public class CommHub:Hub
{
VLCControl outputplayer = new VLCControl();
public void RequestConnectionsList()
{
var databasePath = "--dbpath here--";
var db = new SQLiteConnection(databasePath);
List<string> output = db.Table<VideoSources>().Select(p => p.Name).ToList(); //Gets names from the db
Clients.Client(Context.ConnectionId).CamsInfo(output); //send available connection names to client
}
public void RequestOutStream(string requestedName) //this function is called but i have no idea how to make it work
{
outputplayer.playSelected(requestedName);
}
}
VLCControl:
class VLCControl
{
public Media rtsp;
private const string VIDEO_URL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
private MediaPlayer player;
public static string GetConfigurationString() //using this method in mainwindow player as well
{
string address = Properties.Settings.Default.LocalAddress;
string port = Properties.Settings.Default.LocalPort;
string result=
":sout=#duplicate" +
"{dst=display{noaudio}," +
"dst=rtp{mux=ts,dst=" + address +
",port=" + port + ",sdp=rtsp://" + address + ":" + port + "/go.sdp}";
return result;
}
public void playSelected(string inputAddress)
{
var databasePath = "D:\\Projects\\Sowa\\Sowa\\Serwer\\VideoSources.db";
var db = new SQLiteConnection(databasePath);
string input = db.Table<VideoSources>().FirstOrDefault(p => p.Name == "test").Address;
db.Close();
var rtsp = new Media(MainWindow._libvlc, input, FromType.FromLocation);
rtsp.AddOption(VLCControl.GetConfigurationString());
player.Stop();
player.Play(new Media(MainWindow._libvlc, VIDEO_URL, FromType.FromLocation));
}
}
The players are definitely working - when i create a mediaplayer in mainwindow it does indeed output as expected.
I think your question can be rephrased as "How can I call a method on my UI from a SignalR Hub"
For that, you have several options :
If you are using ASP.net core's SignalR, you can use dependency injection to inject either your window or an accessor to your window
You can get your main window with (MyWindow)Application.Current.MainWindow. What you do with it is up to you then
You can create a static class that will hold a reference to your component directly. This example assumes you have only one view at a time in your application.
public static class ViewAccessor {
public static MyView View { get; set; }
}
In your view constructor, after InitializeComponents:
ViewAccessor.View = this;
In your hub :
ViewAccessor.View.Play(...);
I have a problem with my application on iOS only (iPad 9.7" 11.3.1), it works perfectly on the simulator and on Android device.
When the app is launched for the first time, the user has to log in. This works fine. After that, the menu form is launched and a Dialog is shown on onShowCompleted():
if (!Preferences.get("download", false)) {
dialog = new Dialog("...");
dialog.setLayout(new BorderLayout());
SpanLabel label = new SpanLabel("...");
dialog.addComponent(BorderLayout.CENTER, label);
dialog.show(Display.getInstance().getDisplayHeight() / 5, ..., ..., ...);
}
In the constructor, a method that downloads informations is launched :
if (!Preferences.get("download", false)) {
dlReferentiel();
}
The method :
public void dlReferentiel() {
source = DataSource.getInstance();
// I also tried with invokeAndBlock() but doesn't work
/*
Display.getInstance().invokeAndBlock(() -> requestS());
Display.getInstance().invokeAndBlock(() -> requestB());
Display.getInstance().invokeAndBlock(() -> requestZ());
Display.getInstance().invokeAndBlock(() -> requestA());
*/
requestS();
requestB();
requestZ();
requestA();
}
The requestX methods get informations from server with ConnectionRequest :
(Exemple with requestA() which needs to be the last because it disposes the dialog, it is the only one that calls the UI)
public void requestA() {
ConnectionRequest connectionRequest = new ConnectionRequest() {
ArrayList<A> as = new ArrayList<>();
#Override
protected void readResponse(InputStream in) throws IOException {
JSONParser json = new JSONParser();
Reader reader = new InputStreamReader(in, "UTF-8");
Map<String, Object> data = json.parseJSON(reader);
for (String s : data.keySet()) {
as.add(new A(s, (String) data.get(s)));
}
}
#Override
protected void postResponse() {
source.createAllA(as); // makes insertions with Transaction
ToastBar.showErrorMessage("Référentiel téléchargé", 10);
dialog.dispose();
Preferences.set("download", true);
}
};
connectionRequest.setUrl(URL_A);
connectionRequest.setPost(true);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
I was able to see some logs with a Mac. Each time, the app crashes after the Dialog is shown and few insertions are made. The same error message is output :
HW kbd: Failed to set (null) as keyboard focus
Unable to get short BSD proc info for 513: No such process
Unable to get proc info for 513: Undefined error: 0
I search for informations about this issue but nothing interesting with Codename One.
I don't know what to do with this error, I tried some things like using invokeAndBlock() or changing build hints like ios.keyboardOpen (just because there is "keyboard" in it) but nothing worked.
Thanks for the help.
I face strange execution behaviors in login test methods. I run this code Under selenium Grid. and Grid is configured as a standalone server. So, first I start the selenium grid(Hub\Node) using the batch file to execute by tests.
Following is my class and specs.
code:
1. pojDataSource.java:
public class pojDataSource {
private static WebElement element = null;
private static List<WebElement> elements = null;
public static WebElement txt_UserName(WebDriver driver){
driver.findElement(By.id("txtUserName")).clear();
element = driver.findElement(By.id("txtUserName"));
return element;
}
public static WebElement txt_Password(WebDriver driver){
driver.findElement(By.id("txtPassword")).clear();
element = driver.findElement(By.id("txtPassword"));
return element;
}
}
clsConstant.java:
public class clsConstant {
public static final String URL = "http://localhost:1234/";
public static final String Username = "username";
public static final String Password = "password";
}
ModuleTest.java:
public class ModuleTest {
public RemoteWebDriver mDriver = null;
public DesiredCapabilities mCapability = new DesiredCapabilities() ;
public WebElement mWebElement = null;
public String mBaseURL = clsConstant.URL;
public static clsExcelSampleData mAddConnectorXls;
#Test
public void beforeMethod() throws Exception {
WebDriverWait wdw =null;
mCapability.setCapability("platform", org.openqa.selenium.Platform.WINDOWS);
mCapability = DesiredCapabilities.firefox();
mCapability.setVersion("45.0.2");
mDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"), mCapability);
mDriver.get(mBaseURL);
mDriver.manage().window().maximize();
pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username ) ;
pojDataSource.txt_Password(mDriver).sendKeys(clsConstant.Password ) ;
pojDataSource.btn_LogIn(mDriver).click();
}
When I execute the code in DEBUG mode in eclipese IDE it shows me the strange behaviors. First it start browser and open the mBaseURL successful with login screen. After loading page it shows default userName\password in browser.
Now when debug point comes to pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username ); line. By pressing F5 my debug point goes to pojDataSource.txt_Password(); line and it fetch wrong password and script execution fails. I worry about how this will be happens if my debug point is at username but still it goes to fetch value of password?
Tried solutions:
1. As I use Firefox browser to run test. I clear my password from browser catch.
Recheck the WebElements IDs and make sure they are reachable by WebDriver while debugging. Also try to avoid using 'static' to WebElements. Take a look on Page Objects Pattern.
I have an issue with the printing of XPS documents. The first print works correctly but then the print dialog and the prints appears corrupted as you can see in that image.
I tried to use other overloads of the Write function such as the one using a DocumentPaginator as a parameter or the PrintDocument function of the print dialog but it didn't work either.
I noticed that the results depend on the choice of printer. Using the Microsoft XPS Document Writer works correctly but use a real printer or a PDF printer didn't.
Here's the simplest code that reproduces the issue :
public void Execute(object parameter)
{
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
PrintDocument(
"xps_document_filename.xps",
printDialog);
}
}
private static void PrintDocument(string documentPath, PrintDialog printDialog)
{
using (var xpsDocumentSource = new XpsDocument(documentPath, FileAccess.Read))
{
XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
xpsDocumentWriter.Write(xpsDocumentSource.GetFixedDocumentSequence());
}
}
I have opened the website and applied the Login then popup window opens, i want to click from window popup but i am not able to switch on popup.
driver.get("https://hdfcbank.com/");
driver.findElement(By.id("loginsubmit")).click();
String loginWindow = driver.getWindowHandle();
driver.switchTo().window(loginWindow);
driver.findElement(By.xpath("//*[#id='wrapper']/div[6]/a/img")).click();
I am not able click on popup element at line 5. can you check the code.
Check the accepted answer for a similar question
How to handle Pop-up in Selenium WebDriver using Java
You need to - getWindowHandles - & then iterate over them.
Here is the working solution in case you still haven't figured it out (this is for the HDFC example)...
String test_URL = "http://www.hdfcbank.com/";
String css_login = "img#loginsubmit";
String css_popup_continue = "img[alt='Continue']";
browser = new FirefoxDriver();
browser.navigate().to(test_URL);
List<WebElement> objLogin = browser.findElements(By.cssSelector(css_login));
if (objLogin.size() > 0) {
objLogin.get(0).click();
String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator<String> windowIterator = browser.getWindowHandles().iterator();
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
if (popup.getTitle().contains("NetBanking")) {
List<WebElement> objPopupElement = popup.findElements(By.cssSelector(css_popup_continue));
if(objPopupElement.size() > 0){
System.out.println("Switched to Popup and found element...");
objPopupElement.get(0).click();
//Do any other operations...
break;
}
}
}
//always safe to switch back to parent window to avoid any null pointers, unless parent process got closed...
browser.switchTo().window(parentWindowHandle);
}
else {
System.out.println("Logon button not found...");
}