How do I delete an edge? - cytoscape.js

The documentation isn't clear on how to delete an edge. I've tried
this.cyNetwork.remove("edge[id == #" + id +"]");
this.cyNetwork.remove("edge[id == " + id +"]");
this.cyNetwork.remove(id);
All of this just says the selector is invalid.

Try this.cyNetwork.$id(id).remove(); Check the docs for get element by id https://js.cytoscape.org/#cy.getElementById remove element https://js.cytoscape.org/#eles.remove

Related

what to do for non present DIV tag. Using Selenium & Python

I'm trying to extract information with help of selenium and python from this container "PROJECT INFORMATION" //www.rera.mp.gov.in/view_project_details.php?id=aDRYYk82L2hhV0R0WHFDSnJRK3FYZz09
but while do this I was getting this error
Unable to locate element:
{"method":"xpath","selector":"/html/body/div/article/div2/div/div2/div2/div2"}
after studying about it I found that this highlighted div is missing and there are many places in this container where div is missing. How am I supposed to do that? I want information only from the right side of the table
MY CODE:
for c in [c for c in range(1, 13) if (c == True)]:
row = driver.find_element_by_xpath("/html/body/div/article/div[2]/div/div[2]/div["+ str(c) +"]/div[2]").text
print(row, end=" ")
print(" ")
else:
print('NoN')
error:
no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/article/div[2]/div/div[2]/div[2]/div[2]"}
(Session info: chrome=83.0.4103.106)
The fields highlighted are two different cases. While for "Registration Number" the required div does not exist, for "Proposed End Date" it exists but contains only white space.
Give this a try instead of the for c... loop. It should handle both cases.
#find parent element
proj_info=driver.find_element_by_xpath("//div[#class='col-md-12 box']")
#find all rows in parent element
proj_info_rows = proj_info.find_elements_by_class_name('row')
for row in proj_info_rows:
try:
if row.find_element_by_class_name('col-md-8').text.strip() == "":
print(f"{row.find_element_by_class_name('col-md-4').text} contains only whitespace {row.find_element_by_class_name('col-md-8').text}")
print('NaN')
else:
print(row.find_element_by_class_name('col-md-8').text)
except SE.NoSuchElementException:
print('NaN')
You need this import:
from selenium.common import exceptions as SE

noflo 0.5.13 spreadsheet example broken?

I am new to noflo and looking at examples in order to explore it. The spreadsheet example looked interesting but I couldn't make it run. First, it takes some time and manual debugging to identify missing components, not a big deal and I believe will be improved in the future, for now the error message I get is
return process.component.outPorts[port].attach(socket);
^
TypeError: undefined is not a function
Apparently, before this isAddressable() was also undefined. Checked with this SO issue but I don't have any noflo 0.4 as a dependency anywhere. Spent some time to debug it but seemingly stuck at it, decided to post to SO.
The question is, what are the correct steps to run the spreadsheet example?
For reproduction, here is what I have done:
0) install the following components
noflo-adapters
noflo-core
noflo-couchdb
noflo-filesystem
noflo-groups
noflo-objects
noflo-packets
noflo-strings
noflo-tika
noflo-xml
i) edit spreadsheet/parse.fbp, because first error was
throw new Error("No outport '" + port + "' defined in process " + proc
^
Error: No outport 'error' defined in process Read (Read() ERROR -> IN Display())
apparently couchdb ReadDocument component does not provide Error outport. therefore replaced ReadDocument with ReadFile.
18c18
< 'tika-app-0.9.jar' -> TIKA Read(ReadDocument)
---
> 'tika-app-0.9.jar' -> TIKA Read(ReadFile)
ii) at this point, received the following:
if (process.component.outPorts[port].isAddressable()) {
^
TypeError: undefined is not a function
and improvised a stunt by checking if isAddressable is defined at this location of code:
## -259,9 +261,11 ##
throw new Error("No outport '" + port + "' defined in process " + process.id + " (" + (socket.getId()) + ")");
return;
}
- if (process.component.outPorts[port].isAddressable()) {
+ if (process.component.outPorts[port].isAddressable && process.component.outPorts[port].isAddressable()) {
return process.component.outPorts[port].attach(socket, index);
}
return process.component.outPorts[port].attach(socket);
};
and either way fails. Again, the question is What are the correct steps to run the spreadsheet example?
Thanks in advance.

How to check image requests for 404 using Selenium WebDriver?

What is the most convenient way using Selenium WebDriver to check if an URL GET returns successfully (HTTP 200)?
In this particular case I'm most interested in verifying that no images of the current page are broken.
Try this:
List<WebElement> allImages = driver.findElements(By.tagName("img"));
for (WebElement image : allImages) {
boolean loaded = ((JavaScriptExecutor) driver).executeScript(
"return arguments[0].complete", image);
if (!loaded) {
// Your error handling here.
}
}
You could use the getEval command to verify the value returned from the following JavaScript for each image on the page.
#Test
public void checkForBrokenImages() {
selenium.open("http://www.example.com/");
int imageCount = selenium.getXpathCount("//img").intValue();
for (int i = 0; i < imageCount; i++) {
String currentImage = "this.browserbot.getUserWindow().document.images[" + i + "]";
assertEquals(selenium.getEval("(!" + currentImage + ".complete) ? false : !(typeof " + currentImage + ".naturalWidth != \"undefined\" && " + currentImage + ".naturalWidth == 0);"), "true", "Broken image: " + selenium.getEval(currentImage + ".src"));
}
}
Updated:
Added tested TestNG/Java example.
I don't think that first response will work. When I src a misnamed image, it throws a 404 error as expected. However, when I check the javascript in firebug, that (broken) image has .complete set to true. So, it was a completed 404, but still a broken image.
The second response seems to be more accurate in that it checks that it's complete and then checks that there is some width to the image.
I made a python version of the second response that works for me. Could be cleaned up a bit, but hopefully it will help.
def checkForBrokenImages(self):
sel = self.selenium
imgCount = int(sel.get_xpath_count("//img"))
for i in range(0,imgCount):
isComplete = sel.get_eval("selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].complete")
self.assertTrue(isComplete, "Bad Img (!complete): "+sel.get_eval("selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].src"))
typeOf = sel.get_eval("typeof selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].naturalWidth")
self.assertTrue(typeOf != 'undefined', "Bad Img (w=undef): "+sel.get_eval("selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].src"))
natWidth = int(sel.get_eval("selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].naturalWidth"))
self.assertTrue(natWidth > 0, "Bad Img (w=0): "+sel.get_eval("selenium.browserbot.getCurrentWindow().document.images[" + str(i) + "].src"))
Instead of traversing in Java, it may be faster to call javascript only once for all images.
boolean allImgLoaded = (Boolean)((JavascriptExecutor) driver).executeScript(
"return Array.prototype.slice.call(document.images).every("
+ "function (img) {return img.complete && img.naturalWidth > 0;});");
One of the alternative solutions is analyzing web server logs after test executing. This approach allows to catch not only missed images, but css, scripts and other resources.
Description of how to do it is here.
Funda for Checking 404:
Basically 404s can be checked via HTTP Response of the URL.
Step 1: Import the Library for HTTPTestAPI
Step 2: Create the HTTPRequest.
String URL="www.abc.com";
HTTPRequest request = new HTTPRequest(URL);
//Get the response code of the URL
int response_code = request.getResponseCode();
//Check for 404:
if(response_code == 404)
FAIL -- THE URL is leading to 404.
else
PASS

How do I show Error Message using Managed Custom Actions with Windows Installer

I am writing a managed custom action. I am using the DTF Framework from Windows Installer Xml to wrap the managed dll into a usable CA dll. The CA does what it is supposed to, but I am still having trouble with error handling:
Dim record As New Record(1)
' Field 0 intentionally left blank
' Field 1 contains error number
record(1) = 27533
session.Message(InstallMessage.Error, record)
The above code produces the following text shown in the MSI log:
MSI (c) (C4 ! C6) [13:15:08:749]: Product: TestMSI -- Error 27533. The case-sensitive passwords do not match.
The error number refers to the code contained in the Error table within the MSI. The Message shown above is correct.
My problem is: Why does Windows Installer NOT create a dialog notifying the user about the error?
MSI can do this, but you need to OR in some extra values for the messageType argument.
eg.
Record record = new Record();
record.FormatString = string.Format("Something has gone wrong!");
session.Message(
InstallMessage.Error | (InstallMessage) ( MessageBoxIcon.Error ) |
(InstallMessage) MessageBoxButtons.OK,
record );
See this thread from the wix-users mailing list for more details.
I have run into the same problem, according to Wix: A Developer's Guide to Windows Installer XML by Nick Ramirez, the log and message methods don't work when a custom action is called from a UI control.
If you want a dialog to show up that contains the message, you must do it yourself.
Here's some code I use to do error handling in managed custom actions that run SQL.
It shows a messagebox if the installation is operating with a full UI.
It's in c# but hopefully you'll get the idea.
private void _handleSqlException(SqlException ex)
{
StringBuilder errorMessage = new StringBuilder();
errorMessage.Append("A SQL error has occurred.");
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessage.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
session.Log(errorMessage);
if (session["UILevel"] == "5")
{
MessageBox.Show(errorMessage);
}
}

Script to change Action Sequence records in an MSI

To solve a problem listed here I've got to change the InstallExecuteSequence .RemoveExistingProducts record in an MSI.
I want to do this as part of the build process rather than mucking around with Orca
Modifying the MSI_SetProperty.js script gives
// MSI_SetActionSequence.js <msi-file> <table> <action> <sequence>
// Performs a post-build fixup of an msi to set the specified table/action/sequence
// Constant values from Windows Installer SDK
var msiOpenDatabaseModeTransact = 1;
var msiViewModifyInsert = 1;
var msiViewModifyUpdate = 2;
var msiViewModifyAssign = 3;
var msiViewModifyReplace = 4;
var msiViewModifyDelete = 6;
if (WScript.Arguments.Length != 4)
{
WScript.StdErr.WriteLine("Usage: " + WScript.ScriptName + " file table action sequence");
WScript.Quit(1);
}
var filespec = WScript.Arguments(0);
var table = WScript.Arguments(1);
var action = WScript.Arguments(2);
var sequence = parseInt(WScript.Arguments(3));
var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);
WScript.StdOut.WriteLine("Looking for action:" + action);
try
{
var sql = "SELECT Action, Sequence FROM " + table + " WHERE Action = '" + action + "'";
var view = database.OpenView(sql);
view.Execute();
var record = view.Fetch();
if (record)
{
while (record)
{
WScript.StdOut.Write("Found: " + record.StringData(0) + ", " + record.StringData(1) + ", " + record.StringData(2));
if (record.IntegerData(2) != sequence)
{
WScript.StdOut.WriteLine(" - changing to " + sequence);
record.IntegerData(2) = sequence;
view.Modify(msiViewModifyUpdate,record);
}
else
WScript.StdOut.WriteLine(" - OK");
record = view.Fetch();
}
view.Close();
database.Commit();
}
else
{
view.Close();
throw("Warning - Could not find " + table + "." + action);
}
}
catch(e)
{
WScript.StdErr.WriteLine(e);
WScript.Quit(1);
}
To call this script to perform the change to the action sequence mentioned above you would put the following in a batch file and call that from the post build event e.g. PostBuildEvent = $(ProjectDir)PostBuild.bat
cscript.exe MSI_SetActionSequence.js YOURINSTALLER.MSI InstallExecuteSequence RemoveExistingProducts 1525
Some notes to others out there. I had the "Error 1001. The specified service already exists" problem, and tried the above and it didn't seem to work. Here's what I ran into:
* Make sure the RemovePreviousVersions property on your installer project is set to True. This seems obvious--obvious, that is, if you know about it. By default it is set to False. If False, the above procedure will not solve your problem. *
I have some assemblies installed in the GAC. It appears that when I moved the RemoveExistingProducts sequence that these files were removed from the GAC, but not reinstalled. To solve this I installed all assemblies in the Application Folder. FYI, I'm using VS2010.
Also, another nit-pick. If a user selects "Repair" when attempting to reinstall the same version of a product, they will still get "The specified service already exists" error. If I get time I'll try to fix this. If someone else out there knows how to fix it, could you post?
All that said, thanks for posting this!
The solution provided by Ryan addresses part of the issue I am facing. It does perform full uninstall, followed by install.
However, I have another issue, in my case some of the programs are running in the background. Before the installer can run, the installer complains that some of the files are in use. And gives standard dialog box asking for either to close the application, or restart to complete updating.
Is there a way, eg. a custom action or a setting, to kill the processes running in the background so that the installer goes smoothly?