WebDriver get text from table - webdriver

I use WebDriver and ChromeDriver. How i can fetch text from second table?
I have two tables.
1: click to see photo
2: click to see photo
So, When i try download data from second table i download from first :/
WebElement baseTable = driver.findElement(By.className("grey"));
List<WebElement> tableRows = baseTable.findElements(By.tagName("tr"));
JOptionPane.showMessageDialog(null, tableRows.get(1).getText());
Thank you for your help !

You can use xpath line this for this 'Actualny tryb'
//td[contains(#class,'strong'][contains(text(),'Actualny tryb')]
for this Rejestracja
//img[contains(#style,'vertical-align:middle')][contains(text(),'Rejestracja bezpo')]
Try this code, I don't know JOptionPane:
driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");
String s = driver.findElement(By.xpath("//td[contains(text(),'Status rejestracji przedmiotu')]")).getText();
System.out.println(s);
JOptionPane.showMessageDialog(null, s);

will someone try?
You need download selenium jar from:
http://selenium-release.storage.googleapis.com/3.5/selenium-server-standalone-3.5.3.jar
Download chromedriver: https://chromedriver.storage.googleapis.com/2.32/chromedriver_win32.zip
Import jar file
and copy code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");
Wait();
String s = driver.findElement(By.xpath("//img[contains(#style,'vertical‌​‌​-align:middle)][co‌​nt‌​ains(text(),'Rej‌​estr‌​acja bezpo')]")).getText();
JOptionPane.showMessageDialog(null, s);

Related

Protractor Image didnt upload on dialogue box?

I want to test the image upload functionality using Protractor but my written script didnt work.
This is the image dialogue box.When we click on the dialogue box image it open the window to select desired image.After the selection of image,the box acts like this image.I want to write a script through which i can upload an image and then click on the "Save" button.This is the css of dialogue box.
Given below is the script that i tried but doesn't work. The error message that encountered is this.
var path = require('path');
var fileToUpload = '../new image.jpeg';
var absolutePath = path.resolve('__dirname', fileToUpload);
console.log(absolutePath);
var fileElem=element(by.css('label[for="cropper-file-input"]'));
browser.wait(EC.presenceOf(fileElem), 2000,);
fileElem.sendKeys(absolutePath);
Try the below method. Hope it may help you.
fileUpload(element: ElementFinder, fileElem: ElementFinder, filePath: string): promise.Promise<void> {
//We are using the setFileDetector method to let WebDriver know that we are uploading files from a local directory to a remote server.
//Having this configuration resolves the "Failed: invalid argument: File not found" error that occurs otherwise.
browser.driver.setFileDetector(new utils.remote.FileDetector);
return browser.executeScript(`arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1`, element)
.then(() => fileElem.sendKeys(filePath));
}

How to set permission on document using java code in alfersco?

I am able to set permission using alfresco dashboard but i want to do same with Java code but not get any idea...please if any one have example please upload and till now i am able to do following things.
I am able to create folder,store content,and change the version of content but not able to get any idea's how to set permission so please help me..
Here is some example java code:
String userName = "myusername;"
PermissionService permissionservice = serviceRegistry.getPermissionService();
permissionService.setPermission(nodeRef, userName, PermissionService.CONSUMER, true);
NodeRef dir = fileFolderService.searchSimple(nodeRef, userName);
if (dir == null){
dir = fileFolderService.create(nodeRef, userName, ContentModel.TYPE_FOLDER).getNodeRef();
permissionService.setInheritParentPermissions(dir, false);//should not be visible to others
permissionService.setPermission(dir, "GROUP_managers", PermissionService.COORDINATOR, true);
permissionService.setPermission(dir, "GROUP_basicusers", PermissionService.CONSUMER, true);
}
permissionService.setPermission(dir, userName, PermissionService.CONTRIBUTOR, true);

EPPLUS mimetype causing mcaffee site advisor warning

I have an app which saves CSV and my action simply returns a File response. This works perfectly.
public ActionResult GetUserCSV(string returnUrl)
{
var sb = new StringBuilder();
var users = context.Users.ToList();
sb.AppendLine("Username,Firstname,Lastname");
foreach (var u in users)
{
sb.AppendLine(String.Format("{0},{1},{2}", u.username, u.firstname, u.lastname));
}
string csv = sb.ToString();
var data = Encoding.UTF8.GetBytes(csv);
string filename = "users.csv";
return File(data, "text/csv", filename);
}
I really wanted to save as xslx and I recently found EPPLUS and this tutorial
here which uses a similar approach.
I have copied the tutorial exactly as a test in to my MVC app. It creates the excel file perfectly, however my Mcafee site advisor keeps telling me that the download is dangerous. I have changed the data to data in my db and it is still giving me the same warning.
Am I missing something, or does EPPlus create excel files with inappropriate content?
I wondered if it was the mimetype but I checked and this does appear to be correct.
Has anyone ever experienced this
Uninstall McAfee and use a better AV.

Dynamics AX CompanyImage to Image File

I need to export the images stored in CompanyImage table to a image files.
How can I do it?
Reading the table I obtain a Bitmap field but how to know the type of image to build the correct extension and save it to file?
Finally I found the solution.
To export the image from CompanyImage:
// Grant clrinterop permission.
new InteropPermission(InteropKind::ClrInterop).assert();
image = new Image();
image.setData(companyImage.Image);
result = image.saveImage(#"c:\test.jpg",3);
CodeAccessPermission::revertAssert();
To know the original type:
image.saveType();
The above code wouldn't work right away. Here's the code that would run:
bindata bin = new bindata();
str content;
container image;
CompanyImage companyImage;
;
select companyImage;
image = companyImage.Image;
bin.setData(image);
content=bin.base64Encode();
AifUtil::saveBase64ToFile("c:\\temp\\test.tif", content);

How to switch to a different window using selenium webdriver java?

I am trying to switch to a New window which gets displayed when I click on the Debt Pricing Template. But I am unable to do that as a result of which I am not able to proceed with further scripting... The problem is I am not able to know what should I pass in the switchTo.window() because Pricing Approval Gateway window displays and following is the HTML for the new window:
<*h1 class="pageType noSecondHeader">Pricing Approval Gateway<*/h1>
Following is the code:
LoginPage2.driver.findElement(By.linkText("TEST ORG")).click();
System.out.println("3.Select Dept pricing template button from the organization detail page.");
if(LoginPage2.driver.findElement(By.name("debt_pricing_template")).isDisplayed())
System.out.println("User should able to navigate to Dept pricing template and template display few question, user have answer these question for further navigation.");
LoginPage2.driver.findElement(By.name("debt_pricing_template")).click();
LoginPage2.driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
LoginPage2.driver.switchTo().window("bPageTitle");
Please advise what needs to be added?
I never used it because in my tests I am not using any new windows, but this should help:
Set<string> handlers = driver.getWindowHandles();
if (driver.getWindowHandles().size()>= 1){
for(String handler : handlers){
driver.switchTo().window(handler);
if (driver.getElement(By.tagName("h1")).contains("Pricing")){
System.out.println("Get focus on Popup window");
break;
}
}
}
else System.out.println("No windows founded!");
I am not quite sure with the h1 approach. So if it does not help, try before opening new window storing current window to String:
String mainWindow = driver.getWindowHandle();
Then click the link (or do something else as you are doing now) to open new window. Then to switch to the new window:
Set<string> handlers = driver.getWindowHandles();
for (String handler : handlers){
if (!handler.equals(mainWindow)){
driver.switchTo(handler);
break;
}
}
And then to switch back to original window just do:
driver.switchTo(mainWindow);
Ofcourse the driver variable is expected live instance of
WebDriver
driver.findElement(By.linkText("Go to Billing Summary")).click();
driver.findElement(By.linkText("01 Mar 2016")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("AMS TAX")).click();
driver.findElement(By.linkText("00842")).click();
Set<String> instancewindow= driver.getWindowHandles();
Iterator<String> it = instancewindow.iterator();
String parent =it.next();
String child = it.next();
driver.switchTo().window(child);
driver.switchTo().frame("modalSubWindow");
driver.findElement(By.linkText("View More Vehicle Details>>")).click();
driver.switchTo().window(parent);

Resources