[英]Firefox C# Selenium Can't set a value using sendKeys and JavaExecutor doesn't seem to be affecting it
[英]C# can't seem to use variable value in javascript string
不知道我在哪里錯了,所以我試圖在JavaScript中使用兩個字符串,但是Visual Studio將字符串顯示為錯誤。
編碼:
@{
string animCat = string.Format("#animCat{0}", counter);
string animCatClone = string.Format("#animCatClone{0}", counter);
}
<script type="text/javascript">
if (!jQuery(@animCat)[0].beginElement) {
jQuery(".home-category-container .image-wrapper.clone, .home-category-container .image-wrapper.orig").css({ "filter": "blur(25px)" });
}
jQuery(document).ready(function () {
setTimeout(function () {
if (jQuery(@animCat)[0].beginElement) {
jQuery(@animCat + ", " + @animCatClone)[0].beginElement();
}
else {
jQuery(".home-category-container .image-wrapper").css("filter", "blur(0px)");
}
jQuery(".home-category-container .image-wrapper.orig").css("visibility", "visible");
jQuery(".home-category-container .image-wrapper.clone").remove();
}, 1000);
});
</script>
該圖顯示了我的意思:
不知道我在想什么。
同樣,當我將鼠標懸停在紅色的花樣線條上時,它會顯示“未定義或導入'預定義類型'System.String''”。
還嘗試了if (jQuery('#animCat' + @counter)[0].beginElement) {}
但這不起作用#animCat' + 1
等輸出歡呼聲
好吧,現在可以了,
正如Yeldar Kurmangaliyev建議的那樣,我需要引號,但單引號不能將'@animCat'
加倍
這是有效的代碼:
@{
string animCat = string.Format("#animCat{0}", counter);
string animCatClone = string.Format("#animCatClone{0}", counter);
}
<script type="text/javascript">
if (!jQuery('@animCat')[0].beginElement) {
jQuery(".home-category-container .image-wrapper.clone, .home-category-container .image-wrapper.orig").css({ "filter": "blur(25px)" });
}
jQuery(document).ready(function () {
setTimeout(function () {
if (jQuery('@animCat')[0].beginElement) {
jQuery('@animCat, @animCatClone')[0].beginElement();
}
else {
jQuery(".home-category-container .image-wrapper").css("filter", "blur(0px)");
}
jQuery(".home-category-container .image-wrapper.orig").css("visibility", "visible");
jQuery(".home-category-container .image-wrapper.clone").remove();
}, 1000);
});
</script>
這部分代碼仍然顯示錯誤的紅色花線:
string animCat = string.Format("#animCat{0}", counter);
string animCatClone = string.Format("#animCatClone{0}", counter);
但是,當我構建解決方案並測試它現在可以工作時:)
為所有人加油打氣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.