如何检查元素是否存在,以便在元素存在的情况下可以执行某些步骤。否则,如果元素不存在,则可以执行某些不同的步骤。
我尝试了类似下面的方法,但没有奏效:
Cypress.Commands.add('deleteSometheingFunction', () => {
cy.get('body').then($body => {
if ($body.find(selectors.ruleCard).length) {
let count = 0;
cy.get(selectors.ruleCard)
.each(() => count++)
.then(() => {
while (count-- > 0) {
cy.get('body')
// ...
// ...
}
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个简单的解决方案,它可以与简单的 javascript if else block 或then()部分合并
类似于 Webdriver 协议的以下实现:
driver.findElements(By.yourLocator).size() > 0
好心提醒。谢谢
我是React的新手,经过一些教程后,我正在尝试下面的代码.
我创建了一个组件,从商店向它传递道具,在componentWillMount
我为组件创建一个新状态.渲染很好,直到现在.
接下来,我state
将输入框的值限制在一起,我也有onChange
听众.不过,我无法在现场改变我的价值观.
因为,我从角的背景是,我假设结合输入的值陈述象下面会自动更新属性name
的state
对象.我错了吗?
componentWillMount(){
this.setState({
updatable : false,
name : this.props.name,
status : this.props.status
});
}
//relevant DOM from component's render function
<input className="form-control" type="text" value={this.state.name} id={'todoName' + this.props.id} onChange={this.onTodoChange.bind(this)}/>
onTodoChange(){
console.log(this);
//consoling 'this' here, shows old values only.
//not sure how and even if I need to update state here.
// Do I need to pass new state to this function from DOM
//TODO: send new data to …
Run Code Online (Sandbox Code Playgroud) 上下文是一个相当大的项目,使用 ReactJs 构建,基于 eslint 规则,具有这个 eslint 配置
const DONT_WARN_CI = process.env.NODE_ENV === 'production' ? 0 : 1
module.exports = {
extends: [
'eslint:recommended',
'plugin:jsx-a11y/recommended',
'plugin:react/recommended',
'prettier',
'prettier/@typescript-eslint'
],
plugins: [
'react',
'html',
'json',
'prettier',
'import',
'jsx-a11y',
'jest',
'@typescript-eslint',
'cypress'
],
settings: {
'html/indent': '0',
es6: true,
react: {
version: '16.5'
},
propWrapperFunctions: ['forbidExtraProps'],
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
},
alias: {
extensions: ['.js', '.jsx', '.json']
}
}
},
env: {
browser: true,
node: true,
es6: …
Run Code Online (Sandbox Code Playgroud) 在Polymer元素中"需要"外部javascript的推荐方法是什么?例如,我正在构建一个我要在Slick轮播中显示的视频组组件.
例如,我的代码可能看起来像自定义元素:
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer-jsonp/polymer-jsonp.html">
<polymer-element name="polymer-video-group" constructor="VideoGroupElement" attributes="">
<template>
<style>
/* styles for the custom element itself - lowest specificity */
:host {
display: block;
position: relative;
}
/*
style if an ancestor has the different class
:host(.different) { }
*/
</style>
<!-- Load Data with JSONP Endpoint (in this case Google Spreadsheets)
Source: https://docs.google.com/spreadsheet/ccc?key=0AqZBbhllhMtHdFhFYnRlZk1zMzVZZU5WRnpLbzFYVFE&usp=sharing
https://docs.google.com/spreadsheets/d/1CpXbJHeFrzPpg58lWAsT1N3-QExbX9T5OPVeMfyBqYs/pubhtml
-->
<polymer-jsonp id="jsonp" url="https://spreadsheets.google.com/feeds/list/1CpXbJHeFrzPpg58lWAsT1N3-QExbX9T5OPVeMfyBqYs/od6/public/values?alt=json-in-script&callback=" response="{{response}}"></polymer-jsonp>
<template repeat="{{entry in response.feed.entry}}">
<iframe width="420" height="315" src="//www.youtube.com/embed/{{entry.gsx$id.$t}}" frameborder="0" allowfullscreen></iframe>
</template>
</template>
<script> …
Run Code Online (Sandbox Code Playgroud) 简单的问题,我想在我的控制器范围内将一个函数应用于表达式.
这是我控制器里面的HTML
<p><span ng-if="paginaDetail.pubdate !== '' ">Vanaf {{paginaDetail.pubdate}}</span></p>
Run Code Online (Sandbox Code Playgroud)
这是我的javascript
$scope.formatMysqlTimestampToHumanreadableDateTime = function(sDateTime){
sDateTime = sDateTime.toString();
var sHumanreadableDateTime = sDateTime.substring(8, 10) + "/" + sDateTime.substring(5, 7) + "/" + sDateTime.substring(0, 4);
sHumanreadableDateTime += " " + sDateTime.substring(11, 13) + ":" + sDateTime.substring(14, 16);
return sHumanreadableDateTime;
};
Run Code Online (Sandbox Code Playgroud)
我试图做的是将formatMysqlTimestampToHumanreadableDateTime应用于paginaDetail.pubdate这样
<p><span ng-if="paginaDetail.pubdate !== '' ">Vanaf {{formatMysqlTimestampToHumanreadableDateTime(paginaDetail.pubdate)}}</span></p>
Run Code Online (Sandbox Code Playgroud)
或这个
<p><span ng-if="paginaDetail.pubdate !== '' ">Vanaf {{paginaDetail.pubdate|formatMysqlTimestampToHumanreadableDateTime}}</span></p>
Run Code Online (Sandbox Code Playgroud)
但两种方式都不正确.
第一种方法有效,但在控制台上我发现了这个错误
错误:[$ interpolate:interr] http://errors.angularjs.org/1.2.16/ $ interpolate/interr?p0 = Tot%20%7B%7BformatMysqlTimestampToHumanreadableDateTime(paginaDetail.endpubdate)%7D%7D&p1 = TypeError%3A% 20sDateTime%20is%20undefined t/< @http://mysite.local/js/libs/angular.min.js:6:443 g/r @http://mysite.local/js/libs/angular.min. js:78:354 …
我需要找到一种解决方案,以将React Router的功能与材料ui组件结合在一起。
例如,我有这种情况:路由器和按钮。我试图做到的是将它们混合在一起,然后重新设计它们的样式。
所以从一个简单的链接
<Link className={this.getClass(this.props.type)} to={`${url}`} title={name}>{name}</Link>
Run Code Online (Sandbox Code Playgroud)
我试图创建一个材料UI按钮如下
<Link className={this.getClass(this.props.type)} to={`${url}`} title={name}>
<FlatButton label={name} />
</Link>
Run Code Online (Sandbox Code Playgroud)
但我有以下错误,Javascript中断
invariant.js?4599:38Uncaught Invariant Violation:addComponentAsRefTo(...):只有ReactOwner可以拥有引用。您可能正在向未在组件的
render
方法内部创建的组件添加引用,或者您已加载React的多个副本(详细信息:https : //gist.github.com/jimfb/4faa6cbfb1ef476bd105)。
您知道如何处理这种情况吗?预先谢谢您,如果您需要更多信息,请告诉我
作为问题的标题,这是场景。
一个 shell 脚本文件script.sh
,它执行一些操作,并且在某些时候需要启动节点文件。
#! /bin/bash
node "$(dirname "$0")/script.js" "$input"
echo "${?}\n"
Run Code Online (Sandbox Code Playgroud)
在节点文件中script.js
有一些控件,如果出现错误,脚本将返回错误退出代码。
process.exit(1)
Run Code Online (Sandbox Code Playgroud)
是否可以捕获此错误退出代码以便让命令在 shell 脚本中执行script.sh
?
error Command failed with exit code 1.
顺便说一句,目前执行已因此错误而中断。但我想知道是否可以在 shell 脚本上捕获此错误并继续执行代码的最后部分echo "${?}\n"
。
提前致谢
我在应用程序中使用 Material UI 选项卡并使用 React 测试库。我需要编写用于从一个选项卡导航到另一个选项卡的测试用例。任何人都可以帮我解决这个问题,因为下面的代码无法正常工作。提前致谢。
代码:
const [value, setValue] = React.useState(0)
function handleChange(event, newValue) {
setValue(newValue)
}
Run Code Online (Sandbox Code Playgroud)
<AntTabs value={value} onChange={handleChange} aria-label="Unit information">
<AntTab label="HELLOW1" {...unitTabProps(0)} />
<AntTab label="HELLOW2" {...unitTabProps(1)} />
<AntTab label="HELLOW3" {...unitTabProps(2)} />
<AntTab label="HELLOW4" {...unitTabProps(3)} />
<AntTab label="HELLOW5" {...unitTabProps(4)} />
</AntTabs>
Run Code Online (Sandbox Code Playgroud) 我正在使用Convert在图像上打印一些文本,我想用黑色阴影装饰文本,我尝试了-blur或-gaussian但我无法应用于文本,它仅应用于背景图像。我需要使用-draw命令而不是-annotate。
这是我需要更新阴影的代码
-font "geometricslab703bt-bold-webfont.ttf" -fill White -pointsize 18 -draw "rotate -4 text 350,250 '---- mijn ideale ----'"
Run Code Online (Sandbox Code Playgroud)
提前致谢
我想要实现的目标是存储来自网站的cookie,然后在第二时刻使用它们.这是代码:
保存cookie
let cookie = await page.cookies();
cookie = JSON.stringify(cookie);
fs.writeFile("cookie.txt", cookie, function(err, data){
if (err) {
console.log(err);
} else {
console.log("Successfully Written to File.");
}
});
Run Code Online (Sandbox Code Playgroud)
阅读Puppeteer中的cookie
await page._client.send("Network.clearBrowserCookies");
await injectCookiesFromFile("cookie.txt", page)
async function injectCookiesFromFile(file, page) {
let cb = async function (_cookies) {
console.log("Injecting cookies from file: %s", JSON.stringify(_cookies) );
//await page.setCookie(..._cookies); // method 1
await page.setCookie(_cookies); // method 2
};
fs.readFile(file, async function(err, data) {
if(err) {
throw err;
}
let cookies = JSON.parse(data);
console.log(cookies);
//await cb(cookies); …
Run Code Online (Sandbox Code Playgroud)cookies setcookie google-chrome-devtools google-chrome-headless puppeteer
javascript ×5
reactjs ×4
material-ui ×2
angularjs ×1
bash ×1
client-side ×1
controller ×1
cookies ×1
cypress ×1
draw ×1
eslint ×1
exit-code ×1
imagemagick ×1
node.js ×1
onchange ×1
polymer ×1
puppeteer ×1
react-router ×1
rules ×1
setcookie ×1
sh ×1
shadow ×1
shell ×1
state ×1
text ×1
typescript ×1