我正在尝试打开youtube链接,然后单击频道,但可惜它找不到频道链接。以下链接显示带有红色箭头的目标链接。
因此,这是我的代码,有关更多详细信息,您可以检查此repo:
Driver driver = new Driver();
driver.laodPage("https://www.youtube.com/watch?v=tFPzE4Twj4k");
driver.getCurrentURL();
// driver.getElementById("img").click();
driver.click("//*[@id=\"img\"]"); //Click on video channel
driver.getCurrentURL();
但它抱怨:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="img"]"}
我在chrome控制台上检查了xpath,它给了我21个元素的数组,所以我想也许是因为它。然后,我尝试将其更改为"//*[@id=\"img\"][1]"
,它给了我一个元素,但仍然有问题。
答案 0 :(得分:0)
点击ID“头像”即可:
<ListBox ItemsSource="{Binding WeeklyWeather}"
SelectedItem="{Binding SelectedDailyWeather, Mode=TwoWay}">
//Use ItemTemplate to set how item looks "inside"
//I'll leave design details for you
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Day}"/>
<Image Source={Binding WheatherPicturePath}/>
<TextBlock Text="{Binding Temperature}"/>
<TextBlock Text="{Binding Description}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
//ItemsPanel defines container for items. It can be StackPanel, Wrapanel, Grid, etc
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
//You use this place to design how container normally looks like
<Border Background="White">
//DataTemplate defined above is placed in ContentPresenter
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
//Here we catch "IsSelected" event and re-design our template to visually reflect "selected"
<Trigger Property="IsSelected" Value="true">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Background="Gray">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>