【问题标题】:How do I refer to an attribute that contains a colon? (Selenium/python/xpath/css)如何引用包含冒号的属性? (硒/python/xpath/css)
【发布时间】:2021-08-28 15:25:39
【问题描述】:

example html

除了wire:model 属性之外,每个字段都具有相同的属性,但我无法链接到它,因为我没有足够的经验来编写正确的选择器。 如果您能帮我整理出正确的选择,我将不胜感激。

【问题讨论】:

  • 到目前为止您尝试过什么?你介意分享吗?你有任何错误吗?
  • 根据这些选择器,selenium 找不到元素:'input[wire:model="lastName"]'。

标签: python css selenium xpath laravel-livewire


【解决方案1】:

看看这是否有效:-

textValues = driver.find_elements_by_xpath(".//div[@class='space-y-2']/input")
for e in textValues:
    print(e.get_attribute("wire:model"))

【讨论】:

  • 谢谢,我解决了这个问题,非常感谢你。 textValues = self.browser.find_elements(*ABITUR.wire_model) for e in textValues: if e.get_attribute("wire:model") == 'middleName': ` if clear != (None):` ` e.clear()` ` e.send_keys(middleName)` ` break`
【解决方案2】:

这是一个 CSS 选择器,应该可以用来抓取“lastName”元素,例如:

'input[wire:model="lastName"]'

Here's some hopefully helpful documentation on writing selectors.

【讨论】:

  • 感谢您的回答,这是我在提问之前尝试的第一件事。就我而言,此上诉无效。
【解决方案3】:
.grid > div:first-child input {
   /* this would target Last Name */
 }

.grid > div:nth-child(3) input {
   /* replace 3 with whatever you want. 1 would target Last Name, 2 would target First Name, 3 would target Middle Name
 }

【讨论】:

  • 这个解决方案在我的例子中并不是唯一的,因为大约有 27 个这样的字段,并且如果参数改变它们就会改变。
猜你喜欢
  • 2018-05-01
  • 2012-06-09
  • 1970-01-01
  • 2014-07-31
  • 2021-08-03
  • 1970-01-01
  • 2020-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多