Developing a chrome extension where I collect information about the same product on different shopping sites. I am getting the price and name information of a product on Amazon, I want to learn the price information on other sites using Selenium.
const addProductImageTest = () =>{
const newProduct = {
productImage : document.getElementById("landingImage").src,
productPrice : document.getElementsByClassName("a-price aok-align-center")[0].children[0].innerText,
productAvailability : document.getElementById("availability").children[0].innerText,
productName : document.getElementById("productTitle").innerText,
};
chrome.storage.sync.set({
[product]: JSON.stringify([...allProducts, newProduct])
});
}
The code above is the button click event that I use to get the data of the product on Amazon in contentScript.js.
const {By,Key,Builder,WebElement,JavascriptExecutor} = require("selenium-webdriver");
require("chromedriver");
const sleep = ms => new Promise(r => setTimeout(r, ms));
async function test_case_amazon(){
let chromeDriver = await new Builder().forBrowser("chrome").build();
await chromeDriver.get("https://amazon.com.tr");
await sleep(1000);
await chromeDriver.findElement(By.xpath("//input[@name='field-keywords']")).sendKeys("Corsair iCUE 4000X RGB", Key.RETURN);
await sleep(2000);
await chromeDriver.findElement(By.id("sp-cc-rejectall-link")).click();
await sleep(2000);
await chromeDriver.findElement(By.xpath("//div[@data-component-type='s-search-result']")).click();
let ege = chromeDriver.findElement(By.xpath("//span[@class ='a-price aok-align-center']/span")).getAttribute('innerText');
await sleep(4000);
console.log(ege);
}
test_case_amazon();
This code is the part where I get the product's data with Selenium. I want to use the Selenium code part in contentScript.js for different shopping sites, but I don't know how to change the manifest.json file and import Selenium. Thanks in advance for help.