diff --git a/manifest.json b/manifest.json index 5c15462..df22fa2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { "name": "LetXPath", "short_name": "XPath finder", - "description": "XPath Finder, simple and useful, open-source project", + "description": "XPath Finder, simple and useful, open-source project by LetCode with Koushik", "author": "Koushik Chatterjee", - "version": "2.0.1", + "version": "2.0.2", "manifest_version": 2, "icons": { "16": "assets/16.png", @@ -51,17 +51,6 @@ "devtools_page": "devtools.html", "content_security_policy": "script-src 'self'; object-src 'self'", "homepage_url": "https://www.letcode.in", - "commands": { - "_execute_browser_action": { - "suggested_key": { - "windows": "Alt+L", - "mac": "Alt+L", - "linux": "Alt+L", - "default": "Alt+L" - }, - "description": "LetCode" - } - }, "browser_action": { "default_title": "LetXPath", "default_popup": "popup/popup.html" diff --git a/option/index.html b/option/index.html deleted file mode 100644 index bd8b51b..0000000 --- a/option/index.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - LetXPath Setting - - - - - - - -
-
-
-
- -
-
-

Code snippet

-

Configuration

-
-
-
-
-
- -
-
-
-
-
-
-
Code sample
- -
-
-
-                
-              
-
- -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/option/option.js b/option/option.js index 0d931b6..6130532 100644 --- a/option/option.js +++ b/option/option.js @@ -6,13 +6,14 @@ $(document).ready(function () { embedCodeSample(codeType); setStorage({ langID: codeType }); } - if (result.customLang != undefined) { + else if (result.customLang != undefined) { const codeType = result.customLang; $("select").val(codeType).change(); embedCodeSample(codeType); setStorage({ langID: codeType }); } else { - $("select").val(result.langID).change(); + // $("select").val(result.langID).change(); + embedCodeSample('javas'); setStorage({ langID: 'javas' }); } // set edited values in textarea diff --git a/panel/panel.js b/panel/panel.js index 505f07c..ce0c5fa 100644 --- a/panel/panel.js +++ b/panel/panel.js @@ -1,17 +1,292 @@ chrome.runtime.onMessage.addListener((req, rec, res) => { - console.log(req); - if (req.request === "sendtodevtools") { - buildUI(req.xpath); - } + document.querySelector('.toast').classList.add('d-hide'); + switch (req.request) { + // case "pageInfo": + // console.log(req.request); + // try { + // let ui = ` + // + // + // + // + // + // + // + // + //
Page Title${req.tab.title}
Page URL${req.tab.url}
`; + // jQuery('#eleInfo').empty(); + // jQuery('#eleInfo').append(ui); + // } catch (error) { } + // return true; + + case "send_to_dev": + buildUI(req); + document.getElementById("cssbadge").attributes.getNamedItem('data-badge').value = '0' + if (req.cssPath.length > 0) { + buildCSSUI(req) + } else { + jQuery("#cssbody").empty(); + let ui = `
+

Please select any element to get CSS/XPath

+

more new patterns coming soon :)

+

Did you know LetXPath is an open-source, if you found something wrong fix it :)

+
`; + jQuery("#cssbody").append(ui); + } + if (req.xpathid.length == 0) { + jQuery("#addXPath").empty(); + let ui = `
+

Please select any element to get XPath/CSS

+

more new patterns coming soon :)

+

Did you know LetXPath is an open-source, if you found something wrong fix it :)

+
`; + jQuery("#addXPath").append(ui); + } + return true; + case "anchor": + document.getElementById("xpbadge").attributes.getNamedItem('data-badge').value = 0; + jQuery("#addXPath").empty(); + document.getElementById("cssbadge").attributes.getNamedItem('data-badge').value = 0; + jQuery("#cssbody").empty(); + let ui = `
+

Please select any element to get XPath/CSS

+

more new patterns coming soon :)

+

Did you know LetXPath is an open-source, if you found something wrong fix it :)

+
`; + jQuery("#addXPath").append(ui); + jQuery("#cssbody").append(ui); + generateAxes(req); + return true; + case "axes": + $("#anxp").empty(); + $("#anxp").text(req.data); + return true; + case "fromUtilsSelector": + utilsLocatorUI(req.data); + return true; + case "customSearchResult": + buildSearchUI(req.data); + default: + return true; + } }) +let devtools_connections = chrome.runtime.connect({ name: "ortoni_devtools_message" }); -function buildUI(data) { - // document.write(data); - chrome.storage.local.get(["len"], (data) => { - // document.write(data.len); - let display = document.getElementById("display"); - display.textContent = ''; - display.textContent = data.len; +function buildSearchUI(data) { + jQuery("#insertsearch").empty(); + let ui = ` + `; + $("#insertsearch").append(ui); +} - }) +function utilsLocatorUI(data) { + let len = data.length; + if (len > 0) { + let ui = ` + + + + + + + + ${getTR()} + +
SelectNameXPath
`; + $("#show").append(ui); + } + function getTR() { + let tr = ''; + for (let i = 0; i < data.length; i++) { + tr += ` + ${data[i][1]} + ${data[i][2][0][2]}`; + } + return tr; + } +} +// generate axes based on user inputs +function generateAxes(req) { + // Bring the panel to active + $('#tab_header li.tab-item').removeClass('active'); + $("#tab_header li.tab-item[data-option='3']").addClass('active'); + $('#tab_container .container_item').removeClass('active'); + $('div[data-item="3"]').addClass('active'); + jQuery("#anchorXPath").empty(); + let ui = `
+
+
+ ${req.data.defaultXPath} +
+
+
+
+
+

Parent Element

+ ${sourceElement(req.data.src)} +
+
+
+

Child Element

+ ${targetElement(req.data.dst)} +
+
` + jQuery("#anchorXPath").append(ui); +} +// Build the source element +function sourceElement(element) { + let ui = ''; + for (let i = 0; i < element.length; i++) { + if (i == 0) { + ui += `
+ +
` + } else { + ui += `
+ +
`; + } + } + return ui; +} +// Build the target element +function targetElement(element) { + let ui = ''; + for (let i = 0; i < element.length; i++) { + if (i == 0) { + ui += `
+ +
` + } else { + ui += `
+ +
`; + } + } + return ui; +} +// -------- based on the snippet type show the code ---------- +function buildUI(data) { + jQuery("#addXPath").empty(); + if (data.webtabledetails != null) { + let table = `
+ Table Info - Total no.of table ${data.webtabledetails.totalTables} +
+
+ Table unique locator + ${data.webtabledetails.tableLocator} +
+
+ +
+
+
+
+ Locator for selected row + ${data.webtabledetails.tableData} +
+
+ +
+
+
`; + jQuery("#addXPath").append(table); + } + let len = data.xpathid; + document.getElementById("xpbadge").attributes.getNamedItem('data-badge').value = len.length + for (let i = 0; i < len.length; i++) { + generateXPathUI(data, i); + } +} +// -------- Build XPath UI --------- +function generateXPathUI(data, i) { + let ui = `
+ ${i + 1}. ${data.xpathid[i][1]} +
+
+ ${data.xpathid[i][2]} +
+
+ +
+
+
`; + jQuery("#addXPath").append(ui); +} +// ------- build drop-down for snippet based on element type ------- +function getSelectionValues(data, i, xp, isCSS) { + // let xp = data.xpathid; + let finalOP; + let t = ''; + if (isCSS) { + t = 'CSS'; + } else { + t = xp[i][1] + } + let type = data.type; + let tag = data.tag; + switch (tag) { + case "textarea": + finalOP = ` + + ` + break; + case "input": + if (type === "submit" || type === "radio" || type === "checkbox") { + finalOP = ` + + ` + } else { + finalOP = ` + + ` + } + break; + case "img": + finalOP = ` + + ` + break; + default: + finalOP = ` + + ` + break; + } + return finalOP; +} +function buildCSSUI(data) { + document.getElementById("cssbadge").attributes.getNamedItem('data-badge').value = data.cssPath.length + jQuery("#cssbody").empty(); + let ui = ''; + for (let i = 0; i < data.cssPath.length; i++) { + ui += `
+ ${i + 1}. ${data.cssPath[i][1]} +
+
+ ${data.cssPath[i][2]} +
+
+ +
+
+
`; + } + jQuery("#cssbody").append(ui) } \ No newline at end of file diff --git a/panelconfig.js b/panelconfig.js index 99ca8da..e3641c8 100644 --- a/panelconfig.js +++ b/panelconfig.js @@ -382,28 +382,28 @@ function pySnippet(type, codeType, codeValue, variable) { // getAttribute Collection based XPath //input[@placeholder='first name & last name'] firstName" false switch (codeType) { case "CSS": - str = `find_element_by_css_selector("${codeValue}")`; + str = `driver.find_element(by=By.CSS_SELECTOR, value="${codeValue}")`; break; case "Unique Class Atrribute": - str = `find_element_by_class_name("${codeValue}")`; + str = `driver.find_element(by=By.CLASS_NAME, value="${codeValue}")`; break; case "Unique TagName": - str = `find_element_by_tag_name("${codeValue}")`; + str = `driver.find_element(by=By.TAG_NAME, value="${codeValue}")`; break; case "Link Text": - str = `find_element_by_link_text("${codeValue}")`; + str = `driver.find_element(by=By.LINK_TEXT, value="${codeValue}")`; break; case "Unique ID": - str = `find_element_by_id("${codeValue}")`; + str = `driver.find_element(by=By.ID, value="${codeValue}")`; break; case "Unique Name": - str = `find_element_by_name("${codeValue}")`; + str = `driver.find_element(by=By.NAME, value="${codeValue}")`; break; case "Unique PartialLinkText": - str = `find_element_by_partial_link_text("${codeValue}")`; + str = `driver.find_element(by=By.PARTIAL_LINK_TEXT, value="${codeValue}")`; break; default: - str = `find_element_by_xpath("${codeValue}")`; + str = `driver.find_element(by=By.XPATH, value="${codeValue}")`; break; } switch (type) {