【问题标题】:How to write xpath for Select name class for the below scenario in Javascript?如何在Javascript中为以下场景编写选择名称类的xpath?
【发布时间】:2020-04-16 19:35:02
【问题描述】:

你好,

我正在尝试从卡片列表中选择一张卡片(如下面的屏幕截图所示),并且它的定位器在“元素”部分中突出显示。这是一个 Select name 类,下面的 xpath 对我不起作用。如果有其他方法可以编写 xpath,您能帮我吗?

//select[@class='co-dropdown__select co-payment-card__select']//option[2]

【问题讨论】:

  • 你需要发布相关的Html而不是截图。其他贡献者很难根据意见发布答案。希望你明白我的意思。

标签: javascript node.js selenium xpath web-applications


【解决方案1】:

试试下面的css选择器

 Select select= new Select(driver.findElement(By.cssSelector("select.co-dropdown_select.co-payment-card__select")));    
 select.selectByIndex(index);

【讨论】:

  • 感谢您的回复。我只是在 javascript 中寻找 xpath :)
  • //*[name()="select" and starts-with(@class,"co-dropdown")]//option[2] 呢?
【解决方案2】:

试试这个:

WebElement dropDownList = driver.findElement(By.cssSelector(".co-dropdown__select.co-payment-card__select")); 
Select card= new Select(dropDownList);
card.selectByIndex(2);

【讨论】:

  • 感谢您的回复 :)
  • 如果对您有帮助,请点赞,以便帮助他人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2011-08-14
  • 1970-01-01
相关资源
最近更新 更多