javascript – If .textContent contains X then click

I’m looking to click on every email in my gmail inbox (first page inbox) that contains/starts with the word “Security” (e.g it will click on the below email)

<span id=":31" class="bog">
<span class="bqe"">
Security alert - please check here
</span>
</span>
</pre>

There are 50 .bog elements (the subject lines of the email preview) in my inbox.

I want to find which of those 50 elements contain “Security”, and click on them. It may contain other words.

I have tried:

const elements = await page.$$(".bog");
var text = await page.evaluate(() => document.querySelector('.bog').textContent);
console.log(text);
if (text.textContent === "Security") {
    text.click();
} else {
    console.log("NO")
}
    const elements = await page.$$(".bog");
    const emails = Array.from(elements);
    emails.forEach((email) => {
        if (email.textContent === 'Security alert') {
           email.click();
           console.log("found");
        }
    })

await page.$$eval('.bog', elements => {
    const element = elements.find(element => element.innerHTML === 'Security alert');
    element.click();
});
emails.forEach((email) => {
   if (email.textContent === 'Security alert') {
      email.click();
      console.log("found");
   }
    console.log(email.textContent)
})

But i really don’t know what to do – would appreciate some guidance. All of them gave me varying errors, but i notice when i try to do if X.textContent i often get an undefined error?

Let me know if i should give any more information.

Thanks!

timeline – Hover and Click action on same object on touch devices

I am building a timeline widget which has 2 interactions on web.

  • Hover to see a particular duration’s details like duration, start time, assigned name.
  • Click to edit details of the timeline

However, the primary use of the timeline widget is on a tablet (touch device). What could be some ways to achieve these interactions on a touch device?

timeline – Hover and Click on same object on touch devices

I am building a timeline widget which has 2 interactions on web.

  • Hover to see a particular duration’s details like duration, start time, assigned name.
  • Click to edit details of the timeline

However, the primary use of the timeline widget is on a tablet (touch device). What could be some ways to achieve these interactions on a touch device?

Is it permissible to toggle selection of items in a table with a single click?

I am working on an (existing) UI that has a feature where the selection in one table drives the content of a second table:

  • Table 1 shows a list of notifications, Table 2 shows a list of bank transactions

  • If an notification is selected in Table 1, Table 2 shows a list of bank transactions related to the selected notification (Table 2 is filtered by the Table 1 selection)

  • If no notification is selected in Table 1, Table 2 all the bank transactions (Table 2 is not filtered – it is as if all the notifications have been selected)

Currently, the UI works as:

  • The initial state is for nothing to be selected in Table 1 (all bank transactions are shown in Table 2)

  • Clicking on a notification in Table 1 selects that notification

  • Clicking a second time on the selected notification deselects the notification (nothing is selected)

Here is the problem – we ran a usability test, and users didn’t do well with this interaction. They clicked on a notification to select it, but sometimes clicked again (or double-clicked) and didn’t realize that this had inadvertently deselected the notification. This led to errors in task completion.

The explanation for this is that clicking on an item to deselect it is not normal behavior for a selectable table. I feel that something needs to be done, but the development team is split on how to solve it:

  1. Don’t change anything. It’s a major part of a UI that will receive heavy daily use. Users will learn this behavior. Plus, there’s a precedent from brushing behavior in charts, where clicking on a point in a chart selects it and clicking again deselects it (driving the content of a second chart, or a table)
  2. Do not deselect the notifications on click, but add an additional control to return Table 1 to the deselected state (such as a ‘Remove notification selection’ button, or something like that)
  3. (Not really being considered, but here for completeness) If the user wants to see the transactions for all notifications, make them actually select all items in the table. For various reasons, this isn’t feasible

Any thoughts? Any other ideas how to solve this? The additional controls required by solution ‘2’ seem clumsy, and proponents are arguing that solution 1 is the cleanest and most efficient, and that there’s nothing to worry about in the long term. My worry is that the habits built up by interacting with tables for which click doesn’t toggle selection on and off will be hard to overcome, and lead to errors even after repeated use. Am I worrying unncessarily?

web access – Get file downloaded from click in WebSession?

I’m downloading a file by clicking a button from chrome with the WebDriver functionality:

sess = StartWebSession(Visible->True)
WebExecute(sess, "ClickElement" -> el) (* el is download button *)

This works just fine, and when it finishes it gives a success object:

Success("ClickElement",  Association(
 "MessageTemplate" :> "`command` was successful.", 
  "MessageParameters" -> Association("command" -> "ClickElement"), 
  "Element" -> "0.5797105527746262-24"))

My question is two-fold:

  1. I need a file handle to the finished download (and if it failed to download I need to know that).
  2. Why doesn’t it work when session is not visible. In particular, it gives success but doesn’t actually download, for example:
sess = StartWebSession(Visible->False);
WebExecute(sess, 
 "OpenPage" -> "https://datarepository.wolframcloud.com/resources/Patient-Medical-Data-for-Novel-Coronavirus-COVID-19");
a = WebExecute(sess, "LocateElements" -> "Tag" -> "a");
p = Position(WebExecute(sess, "ElementText" -> a), 
   "Source Notebook")((1, 1));
WebExecute(sess, "ClickElement" -> a((p)))

enter image description here

sharepoint online – open another teaching bubble on click of heading in Teaching bubble

i have created two teaching bubble , now i want that if user click one of the heading of First Teaching bubble it will open another teaching bubble , below are my teaching bubble code.

            import * as React from 'react';
            import { DefaultButton, IButtonProps } from 'office-ui-fabric-react/lib/Button';
            import { ITravelBriefProps } from './ITravelBriefProps';
            import { TeachingBubble } from 'office-ui-fabric-react/lib/TeachingBubble';
            import { useBoolean } from '@uifabric/react-hooks'; 
            import styles from './TravelBrief.module.scss';
            import {
              getTheme,
              mergeStyleSets, 
              FontWeights,
              ContextualMenu,
              Toggle,
              //DefaultButton,
              Modal,
              IDragOptions,
              IconButton,
              IIconProps,ITeachingBubbleProps, shouldWrapFocus
            } from 'office-ui-fabric-react';
            import { readyException } from 'jquery';
            import { TeachingBubbleBasicNext } from './Teaching copy';
            const iconButtonStyles = {
              alignItems: 'normal',
              root: {
                color: '#dd1d21',
                marginLeft: 'auto',
                marginTop: '2px',
                marginRight: '2px',
                
                
              },
              rootHovered: {
                color: '#dd1d21',
              },
            };

            const ArrowIcon: IIconProps = {  iconName: 'OfficeChat' };




            function show()

            {


            }

            const examplePrimaryButtonProps: IButtonProps = {
              
              children: 'Yes',
              onClick: function () {
                window.open("")
            }

            }

            const constheadline :ITeachingBubbleProps={

             headline:""

            }

            export const TeachingBubbleBasicExample: React.FunctionComponent = () =>{
              const (teachingBubbleVisible, { toggle: toggleTeachingBubbleVisible }) = useBoolean(false);
              
             

              const exampleSecondaryButtonProps: IButtonProps = React.useMemo(
                () => ({
                  children: 'Maybe later',
                  onClick: toggleTeachingBubbleVisible
                  
                }),
                (toggleTeachingBubbleVisible),
                   
              );

               return (
                <div>
                  <div> <IconButton
                        styles={iconButtonStyles}
                        iconProps={ArrowIcon}
                        ariaLabel="Close popup modal"
                        onClick={toggleTeachingBubbleVisible}
                        id="targetButton"
                    text={teachingBubbleVisible ? 'Hide TeachingBubble' : 'Show TeachingBubble'}
                      />  <label className={styles.label} onClick={toggleTeachingBubbleVisible} ></label> 
            </div>
            {/*       <DefaultButton
                    id="targetButton"
                    onClick={toggleTeachingBubbleVisible}
                    text={teachingBubbleVisible ? 'Hide TeachingBubble' : 'Show TeachingBubble'}
                  /> */}

                  {teachingBubbleVisible && (
                      
                    <TeachingBubble
                      target="#targetButton"
                      // primaryButtonProps={examplePrimaryButtonProps}
                      // secondaryButtonProps={exampleSecondaryButtonProps}
                      onDismiss={toggleTeachingBubbleVisible}
                      
                    >
                   <ul>
                  <li className={styles.label}>  <a href="#" >get more info</a>. </li>

              </ul>

              

                    </TeachingBubble>

                    

                  )}

                </div>
              );
            };

second teaching bubble which should open on click of get more info

            import * as React from 'react';
            import { DefaultButton, IButtonProps } from 'office-ui-fabric-react/lib/Button';
            import { ITravelBriefProps } from './ITravelBriefProps';
            import { TeachingBubble } from 'office-ui-fabric-react/lib/TeachingBubble';
            import { useBoolean } from '@uifabric/react-hooks';
            import styles from './TravelBrief.module.scss';
            import {
              getTheme,
              mergeStyleSets, 
              FontWeights,
              ContextualMenu,
              Toggle,
              //DefaultButton,
              Modal,
              IDragOptions,
              IconButton,
              IIconProps,ITeachingBubbleProps
            } from 'office-ui-fabric-react';
            import { PropertyPaneSlider } from '@microsoft/sp-property-pane';
            const iconButtonStyles = {
              alignItems: 'normal',
              root: {
                color: '#dd1d21',
                marginLeft: 'auto',
                marginTop: '2px',
                marginRight: '2px',
                
                
              },
              rootHovered: {
                color: '#dd1d21',
              },
            };

            const ArrowIcon: IIconProps = {  iconName: 'OfficeChat' };

            interface ModernProps {
              pdata: number;
              }



            const examplePrimaryButtonProps: IButtonProps = {
              
              children: 'Yes',
              onClick: function () {
                location.href = "" 
            }

            }



            export const TeachingBubbleBasicNext: React.FunctionComponent <{country:any,rating:any}>= (country,rating)=> {
              const (teachingBubbleVisibleNext, { toggle: toggleteachingBubbleVisibleNext }) = useBoolean(false);


              const exampleSecondaryButtonProps: IButtonProps = React.useMemo(
                () => ({
                  children: 'Maybe later',
                  onClick: toggleteachingBubbleVisibleNext,
                  test:""
                  
                }),
                (toggleteachingBubbleVisibleNext),
                   
              );


               return (
                <div className={styles.TeachingbubblePositing}>
                  <div> <IconButton
                        styles={iconButtonStyles}
                        iconProps={ArrowIcon}
                        ariaLabel="Close popup modal"
                        onClick={toggleteachingBubbleVisibleNext}
                        id="targetButtonNext"
                    text={teachingBubbleVisibleNext ? 'Hide TeachingBubble' : 'Show TeachingBubble'}
                      />  <label className={styles.label} onClick={toggleteachingBubbleVisibleNext} ></label> 
            </div>
            {/*       <DefaultButton
                    id="targetButton"
                    onClick={toggleteachingBubbleVisibleNext}
                    text={teachingBubbleVisibleNext ? 'Hide TeachingBubble' : 'Show TeachingBubble'}
                  /> */}

                  {teachingBubbleVisibleNext && (
                      
                    <TeachingBubble
                      target="#targetButtonNext"
                      // primaryButtonProps={examplePrimaryButtonProps}
                      // secondaryButtonProps={exampleSecondaryButtonProps}
                      onDismiss={toggleteachingBubbleVisibleNext}
                      
                    >
                   <ul>
                   <li className={styles.label}>some text goes here </li>
                  
             </ul>


              

                    </TeachingBubble>

                    

                  )}

                </div>
              );
                  
                
                
            };

datetime – Countdown click in JavaScript

const timeControls = document.querySelector('.timer__controls');
const timeLeft = document.querySelector('.display__time-left');
const endTime = document.querySelector('.display__end-time');
let interval;

function secondsToHourMinSec(seconds) {
  const date = new Date(0);
  date.setSeconds(seconds);
  return date.toISOString().substr(11, 8);
}

function advanceCurrentTime(seconds) {
  const date = new Date(0);
  date.setSeconds(Math.floor(Date.now() / 1000) + seconds);
  return date.toLocaleTimeString().substr(0, 7);
}

function displayRemainingTime(seconds) {
  timeLeft.textContent = secondsToHourMinSec(seconds);
}

function displayEndTime(seconds) {
  endTime.textContent = `Be back at ${advanceCurrentTime(seconds)}`;
}

function displayTime(seconds) {
  displayRemainingTime(seconds);
  displayEndTime(seconds);

  interval = setInterval(function() {
    seconds--;
    if (seconds < 0) {
      clearInterval(interval);
      return;
    }
    displayRemainingTime(seconds);
  }, 1000);
}

function startTimer(seconds) {
  clearInterval(interval);
  displayTime(seconds);
}

timeControls.addEventListener('click', e => {
  const button = e.target.closest('button');
  if (button)
    startTimer(parseInt(button.dataset.time));
});

document.customForm.addEventListener('submit', function(e) {
  e.preventDefault();
  const value = this.minutes.value;
  if (value.length !== 0)
    startTimer(parseInt(value) * 60);
  this.reset();
});
html {
  box-sizing: border-box;
  font-size: 10px;
  background: #8e24aa;
  background: linear-gradient(45deg, #42a5f5 0%, #478ed1 50%, #0d47a1 100%);
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 0;
  text-align: center;
  font-family: "Inconsolata", monospace;
}

.display__time-left {
  font-weight: 100;
  font-size: 20rem;
  margin: 0;
  color: white;
  text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.05);
}

.timer {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.timer__controls {
  display: flex;
}

.timer__controls>* {
  flex: 1;
}

.timer__controls form {
  flex: 1;
  display: flex;
}

.timer__controls input {
  flex: 1;
  border: 0;
  padding: 2rem;
}

.timer__button {
  background: none;
  border: 0;
  cursor: pointer;
  color: white;
  font-size: 2rem;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.1);
  border-bottom: 3px solid rgba(0, 0, 0, 0.2);
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  padding: 1rem;
  font-family: "Inconsolata", monospace;
}

.timer__button:hover,
.timer__button:focus {
  background: rgba(0, 0, 0, 0.2);
  outline: 0;
}

.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.display__end-time {
  font-size: 4rem;
  color: white;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Countdown Timer</title>
  <link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="timer">
    <div class="timer__controls">
      <button data-time="20" class="timer__button">20 Secs</button>
      <button data-time="300" class="timer__button">Work 5</button>
      <button data-time="900" class="timer__button">Quick 15</button>
      <button data-time="1200" class="timer__button">Snack 20</button>
      <button data-time="3600" class="timer__button">Lunch Break</button>
      <form name="customForm" id="custom">
        <input type="text" name="minutes" placeholder="Enter Minutes">
      </form>
    </div>
    <div class="display">
      <h1 class="display__time-left"></h1>
      <p class="display__end-time"></p>
    </div>
  </div>

  <script src="https://codereview.stackexchange.com/scripts.js"></script>
</body>

</html>

c# – Difference between methods – onClick.AddListener and On Click under UI button inspector?

Within my Unity Project in my code, (see below), I have a button called Check which executes when CheckPress() function is called. I read two approaches by which this can be done.

Appraoch 1: Using Check.onClick.AddListener(CheckPress); and then attaching script to Canvas. When I press run and click the Check button, this works.

Approach 2: The other approach I read is that, I can attach my script to Canvas. From there I select the button Check from hierarchy, then under inspector I see On Click(), I click + sign and then drag the Canvas and place it in Object (see the attached image), then under No Function I select the CheckButtonBehaviour Script and select the CheckPress(). When I press run and click the Check button, this also works as intended.

I wanted to know if these two approaches are same or different. If they are different, then in which context either approach should be implemented.

using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Threading;
using UnityEditor;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System;
using System.Linq;


public class CheckButtonBehaviour : MonoBehaviour
{

public Button Check;
public Button Play;
public Button NextSignal;

public List<string> signals = new List<string> {"Speech1", "Speech2", "Speech3", "Speech4"};
public List<string> shuffledSignals = new List<string>();
public int index = 1;
public int counter = 3;


private static int localPort;
private string IP;  
public int port = 8050;
IPEndPoint remoteEndPoint;
UdpClient client;


void Start()
{
    
    var rndr = new System.Random();
    shuffledSignals = signals.OrderBy(i => rndr.Next()).ToList();

    IP = "127.0.0.1";
    port = 8050;
    remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP), port);
    client = new UdpClient();
    Play.gameObject.SetActive(false);
    NextSignal.gameObject.SetActive(false);

    Check.onClick.AddListener(CheckPress);

}

public void CheckPress()    
{
    

    byte() data0 = Encoding.ASCII.GetBytes("starting"); ///OLD CODE part
    client.Send(data0, data0.Length, remoteEndPoint);
    Debug.Log("<color=blue>Something is sent to MAX</color> : starting");

    Check.gameObject.SetActive(true);
    Check.interactable = false;
    Check.enabled = false;

    Play.gameObject.SetActive(true);
    NextSignal.gameObject.SetActive(true);

   
}