select combo-box item is not working in edge browser selenium webdriver - selenium-chromedriver

public static void select_Smart_ComboBox_WithCode(String object, String data) {
WebElement ele = getLocatorObject(object);
ele.clear();
ele.sendKeys(data + Keys.ARROW_RIGHT);
String objID = ele.getAttribute(id);
driver.findElement(By.cssSelector(div[id= + objID.substring(0, objID.indexOf(_)) + ] div[id= + data + ] span[class=ffb-match])).click();
}
We are using Selenium WebDriver and I have a method that will enter a value into a combo-box input and we will get dropdown options which we need to select the specific option
This code is working fine in Chrome however in Edge its failing sporadically.
Any thoughts or ideas will be a great help

Related

I have tried to click the button using all techniques. But I am unable to click it

<button class="md-icon-button md-button md-ink-ripple"
type="button" ng-transclude="" ng-click="hide()">
<i class="fa fa-remove ng-scope"></i>
</button>
StepDefinition Code:
#And("^Check whether the Alert message display properly$")
public void alert_msg_display() throws Throwable {
WebElement x= driver.findElement(By.xpath("//button[#data-hover='LOGIN NOW']")); // Path of login button
actionClick(driver, x); // To click login button
WebElement y= driver.findElement(By.xpath("//div[#class='md-dialog-content ng-binding']")); // Path of Alert message text
String a = y.getText();
WebElement z= driver.findElement(By.xpath("//i[#class='fa fa-remove ng-scope']")); // Path of close button of alert popup
waitClick(driver, z); // To wait until close button display
actionClick(driver, z); // Click on close (Note:This operation get FAILED)
String a1 = "Please Enter Branch Id";
driver.findElement(By.xpath("//input[#ng-model='Branchid']")).sendKeys("HO");
actionClick(driver, x);
String b = y.getText();
waitClick(driver, z);
actionClick(driver, z);;
String b1 = "Please Enter Username (Email Id)";
if (a.equals(a1) && b.equals(b1))
test.log(LogStatus.PASS, "Test Case ID: LOG_006 to LOG_010 - Pass");
else
test.log(LogStatus.FAIL, "Test Case ID: LOG_006 to LOG_010 - Fail");
}
Runner File
public void actionClick(WebDriver driver, WebElement a) {
Actions action = new Actions(driver);
action.moveToElement(a).click().build().perform();
}
public void waitClick(WebDriver driver, WebElement a) {
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOf(a));
}
I have tried to click the button using .click method, Actions method, JSExecutor method and also used Wait... But I am unable to click the button. Please, drop your valuable comments. Thanks in advance...
It should operate on pressing the ESCAPE keys. Please try below:
The following 2 ways could work:
Getting the element locator of that image -> Send Escape to the element.
WebElement loginimg = driver.findElement(By.id("AlertX")); loginimg.sendKeys(Keys.ESCAPE);
Or
You can press Escape key by Java Robot class as below:
import java.awt.Robot; import java.awt.event.KeyEvent;
Robot r = new Robot(); r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
from my observations, it is clear that it is not an normal browser alert (if it is, then we can't inspect the elements in it) , so the selenium alert related codes won't work here (like driver.switchToAlert() will throw an No such alert).
Try to click using the following code snippet, it may works
WebElement z= driver.findElement(By.xpath("//button[#class='md-icon-button md-button md-ink-ripple']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", z);

Unable to switch to newly opened tab in chrome using selenium

I opened a new tab from a link in current page. The tab opened but the focus is not shifted to that tab, nor am I able to switch tab using the following two methods I used. I'm using Chrome.
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
BaseClass.driver.findElement(By.xpath(xpathOfLinkToPage2)).sendKeys(selectLinkOpeninNewTab);
//method one
ArrayList<String> tabs = new ArrayList<String>(BaseClass.driver.getWindowHandles());
BaseClass.driver.switchTo().window(tabs.get(1));
//method two
String selectLinkOpeninNewTab2 = Keys.chord(Keys.CONTROL,Keys.TAB);
BaseClass.driver.findElement(By.cssSelector("body")).sendKeys(selectLinkOpeninNewTab2);
// open Site 1
String site_1_Window= driver.getWindowHandle();
System.out.println(site_1_Window);
// open Site 2
Set site_Windows= driver.getWindowHandles();
System.out.println(site_Windows);
for (String site_2_Window: driver.getWindowHandles())
{
System.out.println(site_2_Window);
driver.switchTo().window(site_2_Window);
}
try using:
driver.SwitchTo().Window(driver.WindowHandles.Last());
also see this: http://www.binaryclips.com/2016/03/selenium-webdriver-in-c-switch-to-new.html and this Selenium webdriver selecting new window c#
//count and enter your tab index beside get
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(newTab.get(2));

Labels for tooltips on primefaces barchartseries

I have tried to search both the forum and Google extensively, but I have problems understanding how I should make this work:
PrimeFaces6
I have a BarchartModel based on the tutorial in the ShowCase:
CODE: SELECT ALL
private BarChartModel initStatusBarChart() {
BarChartModel model = new BarChartModel();
ChartSeries statusMessages = new ChartSeries();
statusMessages.setLabel("Label"));
statusMessages.set("Some String 1", list1.size());
statusMessages.set("Some String 2", list2.size());
model.addSeries(statusMessages);
return model;
}
The issue is that on render, I get tooltips the format of
"1, 515" and "2, 432", where 515 and 432 are the sizes of list1 and list2, respectively.
How can I replace 1 and 2 with the values "Some String" 1 and 2 ? Have tried extending highlighter and using dataTipFormat, with no success.
I solved the problem using the datatip editor of the chart model (with Primefaces 6.1, by the way). I used this for a stacked bar chart.
I needed to apply this solution at two places: the backing bean and the JSF page.
In the backing bean I had to set a JavaScript function name this way:
barModel.setDatatipEditor("chartDatatipEditor");
I tried to set it using the corresponding tag attribute in the JSF page but to no effect.
In the JSF I inserted this JavaScript code:
<script type="text/javascript">
function chartDatatipEditor(str, seriesIndex, pointIndex, plot) {
//console.log('chartDatatipEditor: '+str+" - "+seriesIndex+" - "+pointIndex);
var point = seriesIndex+','+pointIndex;
#{bean.datatipsJs}
}
</script>
This JS function gets the chart coordinates as parameters. I concat them so that the following JS code gets easier.
seriesIndex is the index of the chart series. pointIndex is the index on the X scale of the diagram.
To find out what are the correct values for your chart you can uncomment the console.log line above.
The inserted JS code is constructed in the backing bean this way:
private Map<String, String> chartDatatips;
public String getDatatipsJs() {
StringBuilder sb = new StringBuilder("switch ( point ) {\n");
for (String point : chartDatatips.keySet()) {
sb.append("case '").append(point).append("': return '").append(chartDatatips.get(point)).append("'; break;\n");
}
sb.append("default: return 'Unknown point'; break; }");
return sb.toString();
}
The map chartDatatips has the coordinate point as key (e.g., "2,1") and the tooltip as value.
During the chart setup you obviously have to fill this map with useful details ;-)
Like this:
chartDatatips.put("2,5", "Label ...");
...
Hope this helps, if you didn't already solved this.
~Alex
Based on Alex's answer I have come up with this. Only requiring javascript - it displays the label and value:
In the backing bean, set a JavaScript function name this way:
barModel.setDatatipEditor("chartDatatipEditor");
In the HTML file:
function chartDatatipEditor(str, seriesIndex, pointIndex, plot) {
return plot.series[seriesIndex].label + ' - ' + plot.data[seriesIndex][pointIndex];
}

convert html to word not working as example

I am trying to convert html to word. I have found so many codes over the net but none of them works. They are worked with string builder or some with others. I have given a code. In debugger it goes through all the codes without error but no file is getting downloaded.
public void converToWord(string htmlContent,string name)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = name + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:word\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head></head><body>");
strHTMLContent.Append(htmlContent);
strHTMLContent.Append("</body></html>");
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
i got an error it says {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
while the button is in update panel and it does not work properly.everything seems fine but it does not get downloaded.it is a very common problem that happens.just put o a trigger to the button that is firing the event and it will start to work just very much fine.

find HTMLEditor cursor pointer for inserting image

as said in topic: JavaFX HTMLEditor - Insert image function
if want to insert image should add below tag to htmlText of htmlEditor
"<img src=\"" + getClass().getResource(PicName[i])) + "\" width=\"" + target.getImage().getWidth() + "\"height=\"" + target.getImage().getHeight() + "\">")
but if want to add image in cursor position how to do it?
You can achieve this in the following way
Use the ScenicView to explore the HTMLEditor
Get WebView inside HTMLEditor
Get WebEngine of that WebView
Run a JavaScript Code to Insert an image to the caret pos using WebEngine
How To Replace HTML using JS
Link to Original Post
function insertHtmlAtCursor(html) {
var range, node;
if (window.getSelection && window.getSelection().getRangeAt) {
range = window.getSelection().getRangeAt(0);
node = range.createContextualFragment(html);
range.insertNode(node);
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().pasteHTML(html);
}
}
How to Execute JS Code Guide
Node webNode = htmlEditor.lookup(".web-view");
if (webNode instanceof WebView) {
WebView webView = (WebView) webNode;
WebEngine engine = webView.getEngine();
engine.executeScript("alert('helo')"); // add js code here
}
text fileds are have a linear datastructure and can have a sequential position and corresponding location in its view.
but for html view the displayed object location on screen to location in the text mapping is a bit difficult so thats why the html editor cant determine the cursor position
im working on some other workaround to insert image at given cursor position.
try to insert a dummy text as a placeholder like ###inserImage#### then replace it with the actual image tag <img src="file:\c:\testhtmleditor\sample01.jpg" />..
Let's try this piece of code
#FXML private HTMLEditor editor;
...
public void insertTextToCurrentFeatureCursorPosition(String text) {
WebView webView = (WebView) editor.lookup(".web-view");
WebPage webPage = Accessor.getPageFor(webView.getEngine());
webPage.executeCommand("insertHTML", text);
}
Where text is the HTML code which wraps the image