我正在考虑的场景是基本的:
page = driver.open_page(URL)
linkElement = page.find_elements(XPATH)[0]
linkElement.click()
Run Code Online (Sandbox Code Playgroud)
(我假设我正在使用远程机器 - 即远程驱动程序).服务器如何知道要单击的元素.
更一般地说,我找不到硒2实施的概述.也就是说,一方面讲述故事但不在代码中逐行排列的东西,而是比api更详细的东西.
我偶然发现了这个代码高尔夫问题:
给定一个字符串
s
和一个n
表示索引的整数s
,输出第 - 个位置s
的字符n
被删除.
得票最高的答案(截至本文)是在C#中.
s=>n=>s.Remove(n,1);
Run Code Online (Sandbox Code Playgroud)
这种多重=>
语法是什么?它看起来类似于lambda表达式(s,n)=>s.Remove(n,1)
,但我无法弄清楚如何使用此代码.
使用LINQ,我们可以通过以下方式对列表进行左折Aggregate
:
var numbers = new[] { 1, 2, 3, 4 };
var value = numbers.Aggregate((a, b) => a - b); // ((1 - 2) - 3) - 4 == -8
Run Code Online (Sandbox Code Playgroud)
是否有使用LINQ进行正确折叠的类似方法?
var value = numbers.Aggregate(???); // 1 - (2 - (3 - 4)) == -2
Run Code Online (Sandbox Code Playgroud) 我可以用我当前正在做的方式建立一本字典,但我想知道是否有更好更快的方法.我正在尝试使用LINQ SelecMany语句,但遇到了麻烦.
var replyChildren = reply.Children[0];
Dictionary<int, string> slowLog = new Dictionary<int, string>();
for (int i = 0; i < replyChildren.Children.Count(); i++)
{
var ithReplyChildren = replyChildren.Children[i];
for (int j = 0; j < 4; j++)
{
if (j == 3)
{
var jthReplyChildren = ithReplyChildren.Children[j];
for (int k = 0; k < jthReplyChildren.Count; k++)
{
serverInfo += jthReplyChildren.Children[k].TextData; //+ "::";
}
break;
}
serverInfo += ithReplyChildren.Children[j].TextData + ":";
}
slowLog.Add(i, serverInfo);
serverInfo = "";
}
Run Code Online (Sandbox Code Playgroud)
回复将有孩子在里面(第0个元素)然后在那些将有孩子的内部,依此类推.第二个for循环将只有4个孩子,第四个将不得不更深入一步并得到孩子们.
我想确定一个给定的String
startsWith
任何密钥Map
.
简单的解决方案是遍历整个keySet
.
private static Map<String, String> someMap;
private static void method(String line) {
for (String key : someMap.keySet()) {
if (line.startsWith(key)) {
// do something with someMap.get(key);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:是否有更好的数据结构来处理这个问题?
String.StartsWith(char)
并String.EndsWith(char)
在C#7.0 .NET Core 2.0 中新实现.
为什么String.Contains(char)
没有实施?
我通常会听到String.Contains(char)
自己使用创建扩展的常见论点String.IndexOf(c) != -1
.但我不喜欢创建简单的扩展,特别是如果我打算为了可读性而创建一个扩展,这就是我认为这些新的重载是为了(以及为什么我批准了这些更改:)).
public class Note
{
public string account;
public DateTime noteDate;
public string noteText;
}
List<Note> List1;
Run Code Online (Sandbox Code Playgroud)
使用LINQ我正在寻找一种方法来组合noteText
何处account
和noteDate
相同.例如,如果传入列表有三个对象:
List1[0] = "1234", 2017-10-03, "This is a"
List1[1] = "1234", 2017-10-03, " sample note."
List1[2] = "4321", 2017-10-03, "This is another note."
Run Code Online (Sandbox Code Playgroud)
我希望新列表有两个对象:
List2[0] = "1234", 2017-10-03, "This is a sample note."
List2[1] = "4321", 2017-10-03, "This is another note."
Run Code Online (Sandbox Code Playgroud) 我正在使用 Linq 检查字符串值,如果它具有使用以下查询的所有数字:
bool isAllDigits = !query.Any(ch => ch < '0' || ch > '9');
Run Code Online (Sandbox Code Playgroud)
但是如果用户输入一个空格和数字(例如:"123 456"
,"123456 "
),这个检查就会失败。有没有一种方法可以检查空格?
我不想剪掉空格,因为我使用这个文本框来搜索文本,文本之间包含空格。
我想知道这个代码与三元运算符的外观如何
if (a) {
// pass
} else {
b();
}
Run Code Online (Sandbox Code Playgroud)
当a为真时,我们没有(事物)代码执行,但是如果a为假,则有一些代码b()然后执行.
所以我们写道:
a ? : b();
Run Code Online (Sandbox Code Playgroud)
但是当你让代码为真空或者你必须用某些东西替换它时,我不确定这是否正确.实际上我从不使用三元运算符,但我们被要求这样做.
c# ×6
linq ×4
java ×2
.net-core ×1
currying ×1
dictionary ×1
fold ×1
if-statement ×1
lambda ×1
nested-loops ×1
python ×1
selenium ×1
string ×1
textbox ×1
webdriver ×1