i have huge html, i have stored a part of html to a variable. i am trying to click on a specific div in the Variable. var nop = [...document.querySelectorAll('div .field-evaluation-component')].find(el => el.textContent === 'Supervisor ReviewYesNo'); nop variable contains html in it how to click on a div element inside nop variable in pupetter
You need to find the div inside nop.children and then call click() over that element. Just for example you can use something similar:
const nop = [/***/].find(/***/);
if (!nop) {
// do smth if you don't find the nop element
}
// if the nop element is founded
// iterate over all children and call click for each div tag
// ps: update the condition for your needs
for (let i = 0; i < nop.children.length; i++) {
if (foo.children[i].tagName === 'DIV') {
foo.children[i].click();
}
}
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children
Related
I want to add styling to an element only if it contains a particular string. i.e. if(el contains str) {el:style}.
If I wanted just the links containing w3.org to be pink, how would I find <a href="http://www.w3.org/1999/xhtml">article < /a> inside the innerHTML and then style the word "article" on the page.
So far, I can turn ALL the links pink but I can't selectively target the ones containing "www.w3.org".
var links = [...document.body.getElementsByTagName("a")];
for (var i = 0; i < links.length; i++) {
links[i].style["color"] = "#FF00FF";
}
How would I apply this ONLY to the elements containing the string "w3.org"?
I thought this would be so simple at first! Any and all help is appreciated.
While you can't filter by non-exact href values when finding the initial list, and you can't filter by contained text then either, you can filter the list after the fact using plain javascript:
var links = [...document.body.getElementsByTagName("a")];
for (var i = 0; i < links.length; i++) {
if (links[i]['href'].indexOf('www.w3.org') == -1) { continue };
links[i].style["color"] = "#FF00FF";
}
Assuming you want to filter by the href, that is. If you mean the literal text, you would use links[i]['text'] instead.
Attempting to loop through this array, stored in a JSON file. I want to be able to check if a quote is saved and then display it depending on whether it is saved or not.
_toggleCheck() {
var checked = !this.state.checked;
this.setState({ checked: checked });
// For loop to run through arrray and update booleans
for(int i = 0; i<quotesArray.length-1; i++;){
quotes.quotesArray[i].isSaved = checked;
}
this.props.onChange && this.props.onChange(this.props.name, checked);
}
In attempting to do this, I have come across this error and can not resolve it. Line 63 is the beginning of the for loop. I dont know how to use a for loop in react native and cant find any tutorials on line.
for(int i = 0; i<quotesArray.length-1; i++;){
^ remove this semicolon
By the way, are you sure you want i < quotesArray.length - 1 instead of i < quotesArray.length? You're skipping the last element when you add -1.
When I create a list of button and I addTouchEventListener for it, like below code
for (int i = 0; i < btmPlay.size(); i++ )
{
btmPlay.at(i)->addTouchEventListener([&](Ref *sender, ui::Widget::TouchEventType type){
if (type == ui::Widget::TouchEventType::ENDED)
{
CCLOG("%i", i);
}
});
}
when I touch to the first button, the result is 12 ( btmPlay.size() = 13).
What errors?
In your closure, you're capturing the variable i by reference, and that's why clicking any button will print the same value, in this case 12. If, instead, you capture the variable i by value (by replacing [&] with [=]) then each button will print a different value in the range 0-12.
Btw, capturing i by reference in your example is also wrong, because by the time the closure is invoked, the variable is already out of scope, and printing it is UB.
Im needing some help in AS#3 and arrays
Basically i am having trouble of pushing items into a 2D array with errors.
Below is what i have and trying to use:
var j = 0
var i = 0
var mixerArray:Array = new array();
function Mixer()
{
optionLenght = gridOption.sequence_txt.text;// == 8
track_list = gridOption.track_text.text;// == 4
for (j = 0; j <track_list; j++)
{
make_tracks();
for (i = 0; i <optionLenght; i++)
{
item_inside_track();
}
}
function make_tracks(){
tracks = new Tracks();//a large box
MixerArray[j].push(tracks);
}
/* Make little boxes inside big box
..................................................
*/
function item_inside_track(){
box= new Box();//littlebox
MixerArray[j][i].push(box); // iwant to push this box into track[j]
}
basically im trying to create an array that stores values inside of values for example
MixerArray()
[0]TRACK1 = [0]//littlebox ,[1]//littlebox, [2]//littlebox [3]//littlebox etc to 8
[1]TRACK2 = [0]//littlebox ,[1]//littlebox, [2]//littlebox [3]//littlebox etc to 8
[2]TRACK3 = [0]//littlebox ,[1]//littlebox, [2]//littlebox [3]//littlebox etc to 8
[3]TRACK4 = [0]//littlebox ,[1]//littlebox, [2]//littlebox [3]//littlebox etc to 8
This has to be dynamic, as it will constant change..i have cut the addchilds and other code to minimize it to the source area.
So you're basically creating an array of arrays.
The problem here is that you're trying to push items into an element of the second array.
MixerArray[j][i].push(box); // iwant to push this box into track[j]
If you want to push into the J array, you just have to do this:
MixerArray[j].push(box);
However, you need to create the different Arrays contained in MixerArray first. Just push new Arrays into MixerArray in an initialisation function or at the start of your first function . Another issue with your code is that you used:
var mixerArray:Array = new array(); while in the rest of your code you're using:
MixerArray
Make the changes and tell me if it works !
I'm making a dots and boxes game in flash using actionscript 3.
Currently I'm completely stuck as I want the player to click two buttons before a line is displayed. I planned to do something like this using the if statement
if button1 and button2 clicked
line1 visible = true
I've also tried adding eventlisteners with one function
function showLine(e:Event):void {
blue0001.visible = true
}
dot00.addEventListener(MouseEvent.CLICK, showLine);
But as far as I know this can only be used when you want to click one button. Is there anyway to have two eventlisteners satisfyed before the function is carried out?
Also how would I (if i can) use the if statements to carry out this?
You would probably do something like this, pseudo-code:
Assume all of the dots are in a dots array.
for (var i: Number = 0; i < dots.length; i++) {
dots.addEventListener(MouseEvent.CLICK, dotClicked, false, 0, true);
}
dotSelected = null;
function dotClicked(evt:MouseEvent):void {
if (dotSelected && isNeighbor(evt.target, dotSelected)) {
showLineConnecting(evt.target, dotSelected)
dotSelected = null;
} else if (!dotSelected) {
highlightDot(evt.target);
dotSelected = evt.target;
} else {
showError("You must click an adjacent dot");
}
}
At the request of the OP, this is what's going on.
for (var i: Number = 0; i < dots.length; i++) {
dots.addEventListener(MouseEvent.CLICK, dotClicked, false, 0, true);
}
Add an event listener to every dot. Here I am assuming you already have an array of dots defined. Each instance in the Array would be a MovieClip (likely), Sprite, or another DisplayObject.
dotSelected = null;
We will use a variable to keep track of any currently selected dot. Since no dot will be selected when the game starts, we set it to null.
function dotClicked(evt:MouseEvent):void {
if (dotSelected && isNeighbor(evt.target, dotSelected)) {
showLineConnecting(evt.target, dotSelected)
dotSelected = null;
} else if (!dotSelected) {
highlightDot(evt.target);
dotSelected = evt.target;
} else {
showError("You must click an adjacent dot");
}
}
This is the function that will get called when any dot is clicked. For explanation's sake, let's take the first click of the game. dotSelected is null, so the first if is false. The second if though is true, because (!dotSelected) is true. So, we run some function I called highlightDot with the dot as the argument. That function could look something like this:
function hightlightDot(dot:Dot):void {
dot.gotoAndStop("selected");
}
Now a second click is made. Now the first part of the first if, dotSelected, is true. The second part is now evaluated. Again I put in a made up function isNeighbor. The isNeighbor function takes two arguments, the dot that was just clicked and the dot that has already been clicked. This function needs to make sure the two dots are adjacent. This could be something like...
function isNeighbor(dot1:Dot, dot2:Dot):void {
return ((dot1.xGrid == dot2.xGrid && Math.abs(dot1.yGrid - dot2.yGrid) == 1) || (Math.abs(dot1.xGrid - dot2.xGrid) == 1) && dot1.yGrid == dot2.yGrid));
}
The above function assumes that the instances of Dot have some properties xGrid and yGrid which defines where in the playing board they sit. If they are in the same row and 1 column apart they are neighbors. If they are in the same column and 1 row apart they are neighbors.
The last thing that happens in a function showLineConnecting is called. That function will again take the two adjacent dots as arguments. It will then draw a line between them in whatever way you choose to do that. Finally, dotSelected is set back to null, allowing another set of dots to be selected.
One thing I just realized, it would probably be helpful to have an additional property that gets triggered on a Dot when it is connected to all of its neighbors so it could no longer be selected.
You will also need logic to handle knowing that a box has been created. For that you would likely just iterate the possibilities given the line that was just drawn. For each line drawn there are only two possible boxes that have been created. So check them both. Watch out for edges.