我有这个元素:
WebElement element = ...
string val = element.getAttribute("innerHTML");
Run Code Online (Sandbox Code Playgroud)
我想要做的就是innerHTML在我的网页上更改此内容.
可能吗?
请参阅以下元素:
<div class="success"><button class="close" data-dismiss="alert" type="button">×</button>
User 'MyUser' deleted successfully</div>
Run Code Online (Sandbox Code Playgroud)
找到我的元素:
driver.findElement(By.cssSelector("div.success")
Run Code Online (Sandbox Code Playgroud)
所以在找到这个div并使用selenium获取文本getText或getAttribute("innerHTML")返回:
×
User 'MyUser' deleted successfully
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何在没有这个的情况下获得最后一行 x
考虑一下:
val element = ...
String str = element.getAttribute("innerHTML")
Run Code Online (Sandbox Code Playgroud)
所以如果我只想得到这个value就足够用presenceOfElementLocated而不是visibilityOfElementLocated?
我很简单Enum:
public enum StatusMessage
{
Cancel,
Done,
[Description("In process...")]
InProcess,
[Description("We have delay...")]
Delay,
Waiting
}
Run Code Online (Sandbox Code Playgroud)
和GridViewColumn:
我的财产:
StatusMessage StatusMsg;
Run Code Online (Sandbox Code Playgroud)
XAML:
<GridViewColumn Width="180" Header="Status" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding StatusMsg}" Foreground="{Binding StatusMsg,Converter={my:StatusMessageToColorConverter}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Run Code Online (Sandbox Code Playgroud)
我有这个EnumToStringConverter:
public class EnumToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string EnumString;
try
{
EnumString = Enum.GetName((value.GetType()), value);
return EnumString;
}
catch
{
return string.Empty;
}
}
// No need …Run Code Online (Sandbox Code Playgroud) 我尝试LocaDate按格式获取,所以我使用了这个接收日期和搜索格式的函数来解析:
def getLocalDate(date: String): LocalDate = {
val pattern1 = DateTimeFormatter.ofPattern("dd MMM, yyyy")
val pattern2 = DateTimeFormatter.ofPattern("dd MMM yyyy")
val pattern3 = DateTimeFormatter.ofPattern("yyyy-MMM-dd")
val pattern4 = DateTimeFormatter.ofPattern("dd/MM/YYYY")
val pattern5 = DateTimeFormatter.ISO_LOCAL_DATE
val result = Try {
LocalDate.parse(date, pattern1)
} recover {
case _ => LocalDate.parse(date, pattern2)
} recover {
case _ => LocalDate.parse(date, pattern3)
} recover {
case _ => LocalDate.parse(date, pattern4)
} recover {
case _ => LocalDate.parse(date, pattern5)
}
result.get
}
Run Code Online (Sandbox Code Playgroud)
用法:
var s1 = "01/08/2010" …Run Code Online (Sandbox Code Playgroud) 我有一些操作,有时我想停在中间:
bool contine;
foreach (var item in this)
{
if (contine)
{
// do my stuss
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题,foreach有时我需要特定的延迟时间,所以我正在使用Thread.Sleep.因此,当我停止我的操作以防我仍在其中时,Thread.Sleep我的应用程序正在等到此Thread.Sleep结束并且只停止我的操作所以我可以从Thread.Sleep中间退出吗?
更新
我需要特定睡眠的原因是因为我正在播放数据包,并且每个数据包之间都有一个Time stamp因此这就是我需要这个睡眠的原因.
我想计算2个日期之间的随机日期.
所以我有这个功能:
def calculateDates(from: LocalDate, until: LocalDate): Seq[LocalDate] =
{
val ld: LocalDate = new LocalDate()
if (from.compareTo(until) > 1)
return[]
else
return from :: calculateDates(from.plusDays(1), until)
}
Run Code Online (Sandbox Code Playgroud)
我的意见:
01 Jan, 1970
01 Jan, 2015
Run Code Online (Sandbox Code Playgroud)
所以首先我需要更改我的函数只返回一个日期,第二件事是如何将我的输入转换为LocalDate对象?
所以我有这个WebElement(现在处于禁用模式):
<select id="id1" name="name" disabled=""><option value="">Select...</option>
<option value="false">No</option>
<option value="true">Yes</option></select>
Run Code Online (Sandbox Code Playgroud)
不禁用:
<select id="id1" name="name" ><option value="">Select...</option>
<option value="false">No</option>
<option value="true">Yes</option></select>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何检查这个元素是否被禁用?
我有一些从simple读取的值Text file。
这是我的数据:
val data = new ListBuffer[(String, BigDecimal)]
Run Code Online (Sandbox Code Playgroud)
现在,我想在我的项目内添加项目ListBuffer:
data += ("bla bla", 12)
Run Code Online (Sandbox Code Playgroud)
然后收到错误:
类型不匹配; 找到:List [(String,scala.math.BigDecimal)]必需:(String,BigDecimal)数据+ = List((“ bla bla”,12))
所以我有这个2 collections:
import collection.mutable.ListBuffer
val list1 = ListBuffer[(String, String)]()
list1 += (("Italy", "valid"))
list1 += (("Germany", "not valid"))
list1 += (("USA", "not valid"))
list1 += (("Romania", "valid"))
val list2 = ListBuffer[String]()
list2 += "Germany"
list2 += "USA"
list2 += "Romania"
list2 += "Italy"
list2 += "France"
list2 += "Croatia"
Run Code Online (Sandbox Code Playgroud)
我想得到包含具体的公共国家的新列表,condition例如valid结果将是新列表:
Italy, Romania
Run Code Online (Sandbox Code Playgroud) public static IWebElement FindElement(ExpectedConditions expectedConditions, By by, int timeoutInSeconds)
{
DefaultWait<IWebDriver> wait = new DefaultWait<IWebDriver>(driver);
wait.Timeout = TimeSpan.FromSeconds(timeoutInSeconds);
wait.PollingInterval = TimeSpan.FromMilliseconds(10000);
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
IWebElement element =
wait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(by));
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
如何把这个expectedConditions放在我的方法中?
我试着改变:
IWebElement element =
wait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(by));
Run Code Online (Sandbox Code Playgroud)
有了这个:
IWebElement element =
wait.Until<IWebElement>(expectedConditions(by));
Run Code Online (Sandbox Code Playgroud)
并收到此错误:
预期的方法名称.
我想知道List当我试图找到一些WebElement但没有找到时,如何返回空.当然我想避免崩溃,所以这就是我尝试过的:
def getList(): List[WebElement] = {
try {
driver.fineElements(By.xpath("bla bla))
}catch{
case e: TimeoutException => // What should i put here ???
}
}
Run Code Online (Sandbox Code Playgroud) 所以我有这个CSS选择器查询,它返回几个结果:
div[class=b-folders] span[class=b-folders__folder]
Run Code Online (Sandbox Code Playgroud)
我试过只想获得最后一个。
div[class=b-folders] span[class=b-folders__folder]:last-of-type
Run Code Online (Sandbox Code Playgroud)
但是什么也没找到。