简体   繁体   English

Selenium-python无法找到具有某些名称属性的元素

[英]Selenium-python can't find elements with certain name attributes

I'm using selenium-python 2.46.1, and input elements with names like chunk_items-__prefix__-chunk_title don't come up with the following code: 我正在使用selenium-python 2.46.1,并且具有诸如chunk_items-__prefix__-chunk_title类的名称的输入元素没有提供以下代码:

input element is : 输入元素是:

<input id="id_chunk_items-__prefix__-chunk_title" maxlength="255" name="chunk_items-__prefix__-chunk_title" type="text" />

I have tried: 我努力了:

ids = driver.find_elements_by_xpath('//input')
        for ii in ids:
            print ii.get_attribute('name')    # id name as string

or 要么

elem = driver.find_element_by_name("chunk_items-__prefix__-chunk_title")

though 虽然

'assert "chunk_items-__prefix__-chunk_title" in self.driver.page_source' is fine 'assert "chunk_items-__prefix__-chunk_title" in self.driver.page_source'是可以的

Any ideas? 有任何想法吗?

In a webpage(even on simple one) there could be many input tags and you don't want to loop through all of them to find one attribute. 在一个网页中(甚至是简单的网页),可能会有许多输入标签,并且您不想遍历所有输入标签来找到一个属性。 Since the html tag contains id attribute(and I assume that is unique) you can easily find the element and check for any attribute there. 由于html标记包含id属性(并且我认为这是唯一的),因此您可以轻松找到该元素并检查那里的任何属性。

element = driver.find_element_by_id('id_chunk_items-__prefix__-chunk_title')
name = element.get_attribute('name')
assert "chunk_items-__prefix__-chunk_title" in name

Yes, I realise looping through is not the way normally, I should have explained better that this was just to see if they showed up. 是的,我意识到循环不是正常的方式,我应该更好地解释这只是看它们是否出现。

I've found out now that some Javascript is causing issues, so it wasn't an issue with Selenium after all. 我现在发现某些Javascript引起了问题,所以Selenium毕竟不是问题。

Thanks anyway. 不管怎么说,还是要谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM