web scraping - element not interactable with JS and module "selenium-webdriver" - javascript

To continue my script I'm trying to close this small window on this page https://mom.maison-objet.com/fr/marque/16604/britop-lighting-poland?request_type=meeting#xtor=AL-1459
To close it, I'm using JavaScript and the module "selenium-webdriver"
This is what I did:
require("chromedriver");
let swd = require("selenium-webdriver");
let browser = new swd.Builder();
let tab = browser.setChromeOptions().forBrowser("chrome").build();
let tabToOpen =
tab.get("https://mom.maison-objet.com/fr/marque/16604/britop-lighting-poland?request_type=meeting#xtor=AL-1459");
tabToOpen.then(function () {
tab.manage().setTimeouts({ implicit: 1000 })
let click_on_close = tab.findElement(swd.By.css(".icon.icon__cross.lightbox__close"))
;
click_on_close.click()
return;
})
I'm having this error: ElementNotInteractableError: element not interactable.
I don't seem to find how to solve this error. If someone can help me?

Related

AmCharts4 - Unable to load file

I'm showing a chart using AmCharts4 with the URL option to load the data from a PHP file in JSON format. The problem is that sometimes I have an error. In the javascript console, I see the message: net::ERR_NETWORK_IO_SUSPENDED and in the chart the message: Unable to load file. I need to reload the page to load the chart again. I'm not able to find a similar problem on the web, therefore I would be very grateful for help.
const chartTotales = am4core.create('chart-disponibilidad-pastel', am4charts.PieChart);
chartTotales.dataSource.url = 'backend/production.php?opc=4';
chartTotales.dataSource.reloadFrequency = 6000;
const pieSeries = chartTotales.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = 'horas';
pieSeries.dataFields.category = 'tipo';
pieSeries.dataFields.test = '0 min';
pieSeries.slices.template.stroke = am4core.color('#fff');
pieSeries.slices.template.strokeOpacity = 1;
pieSeries.labels.template.text = '{category} {test} {value.formatDuration(\'hh:mm:ss\')} Hrs';
pieSeries.slices.template.tooltipText = '{category} {value.formatDuration(\'hh:mm:ss\')}';
const colorSetTotal = new am4core.ColorSet();
//D72906
colorSetTotal.list = ['#F6F623', '#498561', '#D72906'].map( function(color) {
// #ts-ignore
return new am4core.color(color);
});
You can try setting updateCurrentData to true, this shouldn't remove current data.
chartTotales.dataSource.updateCurrentData= true;
https://www.amcharts.com/docs/v4/reference/datasource/#updateCurrentData_property
Also check Network tab in browser tools to see what is in response from API.
Maybe you are hitting rate limiter.

How to detect App installed on device using getInstalledRelatedApps()

Am trying to use this script found here to detect if my app has been installed on a phone. If so, it should prompt them to open app, if not, it should prompt them to download app. I've followed the tutorial to the letter, from installing manifest.json on server, to adding the script to my app and uploading to playstore and I have added the follow script to my index...
const status = document.getElementById('status');
const ul = document.getElementById('installedApps');
window.addEventListener('load', () => {
// Check to see if the API is supported.
if ('getInstalledRelatedApps' in navigator) {
const divNotSupported = document.getElementById('notSupported');
divNotSupported.classList.toggle('hidden', true);
checkForRelatedApps();
}
});
function checkForRelatedApps() {
navigator.getInstalledRelatedApps().then((relatedApps) => {
status.textContent = `resolved (${relatedApps.length})`;
relatedApps.forEach((app) => {
const lines = [];
lines.push(`<b>id:</b> <code>${app.id}</code>`);
lines.push(`<b>platform:</b> ${app.platform}`);
lines.push(`<b>url:</b> ${app.url}`);
const li = document.createElement('li');
li.innerHTML = lines.join('<br>');
ul.appendChild(li);
});
});
}
<div>
<b>Installed Apps:</b> <span id="status"></span>
<ul id="installedApps">
</ul>
</div>
But when I view page, scroll to the bottom, not is showing.
But on his page, without installing the app, when you visit the page, it says resolved (0).
So I want to know if am doing something wrong with the script? Am I suppose to change something?
His demo can be found here

Remove Measure Toolbar Button from Autodesk Forge Viewer

I am using the autodesk forge viewer and want to remove the 'measure' tool from the toolbar. I have tried the following but it will not remove the 'measure' button
const onToolbarCreated = (e) => {
const settingsTools = viewer.toolbar.getControl('settingsTools')
// settingsTools.removeControl('toolbar-modelStructureTool')
// settingsTools.removeControl('toolbar-propertiesTool')
settingsTools.removeControl('toolbar-settingsTool');
settingsTools.removeControl('toolbar-measureTool');
//settingsTools.removeControl('toolbar-fullscreenTool')
}
All of the other removeControl() functions work other than the one for the measure-tool. Any guidance on how I could remove this button from the viewer would be greatly appreciated!
Cheers!
EDIT: I have tried this without success
const onToolbarCreated = (e) => {
const settingsTools = viewer.toolbar.getControl('settingsTools');
const modelTools = viewer.toolbar.getControl('modelTools');
modelTools.removeControl('toolbar-measurementSubmenuTool');
// settingsTools.removeControl('toolbar-modelStructureTool')
// settingsTools.removeControl('toolbar-propertiesTool')
settingsTools.removeControl('toolbar-settingsTool');
//settingsTools.removeControl('toolbar-measurementSubmenuTool');
//settingsTools.removeControl('toolbar-fullscreenTool')
If you are not planning to use it anymore you can simply unload the extension from your project.
viewer.unloadExtension("Autodesk.Measure");
Measure tool is in modelTools group.
const modelTools = viewer.toolbar.getControl('modelTools')
modelTools.removeControl('toolbar-measurementSubmenuTool')

Beginner question: Two Scripts cancelling each other out?? query selector / function / addEventListener

i'm a beginner in terms of Javascript.
For my project I tried/recreated some tutorials and pasted them in the script Tag in the html file. Now I noticed that 2 of them are not working. It seems like they cancelling each other out: When I delete one script, the other is working and the other way around.
The problem must be pretty basic, but as a beginner I'm not sure what I'm overlooking.
These are the two scripts. The first one is for a toggle button and the second one for the mobile hamburger menu.
var switchButton = document.querySelector('.switch-button');
var switchBtnRight = document.querySelector('.switch-button-case.right');
var switchBtnLeft = document.querySelector('.switch-button-case.left');
var activeSwitch = document.querySelector('.active');
function switchLeft(){
switchBtnRight.classList.remove('active-case');
switchBtnLeft.classList.add('active-case');
activeSwitch.style.left = '0%';
}
function switchRight(){
switchBtnRight.classList.add('active-case');
switchBtnLeft.classList.remove('active-case');
activeSwitch.style.left = '50%';
}
switchBtnLeft.addEventListener('click', function(){
switchLeft();
}, false);
switchBtnRight.addEventListener('click', function(){
switchRight();
}, false);
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const links = document.querySelectorAll('.nav-links li');
hamburger.addEventListener("click", () => {
navLinks.classList.toggle("open");
links.forEach(link => {
link.classList.toggle('fade')
});
//burger animation
hamburger.classList.toggle('toggle');
}```
I can only see that you are missing ); at the end of your code, the closing part of hamburger.addEventListener(.
Also i guess these ``` at the end are typos while trying to format your code in the editor here.
Make sure there is no error printed in your browser console.

Insert richtext or html in word online using office app

I am trying to insert HTML text in a content control using an Office App from Word Online. Unfortunately, it is not working for me. The same code works if I run it on the desktop version of Word.
For Word Online somehow I can insert only plain text and nothing else. Can anyone please help me with this?
This is the complete Word.Run method:
Word.run(function(context) {
var htmlText = ' <h1>Test HTML Text</h1>'
var range = context.document.getSelection();
var myContentControl = range.insertContentControl();
myContentControl.tag = 'Testtag';
myContentControl.title = 'TestTitle';
myContentControl.insertHtml(htmlText, 'end');
myContentControl.cannotEdit = false;
myContentControl.cannotDelete = false;
context.load(myContentControl, 'id');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log('Created content control with id: ' + myContentControl.id);
});
})
Can anyone please help me with what am I missing to achieve the same in word online.

Categories