简体   繁体   English

Selenium Webdrive查找可见元素

[英]Selenium Webdrive find visible element

So i have this form for anti-spam. 所以我有这种形式的反垃圾邮件。 Because of that it creates for each input about 9 or so inputs. 因此,它为每个输入创建大约9个左右的输入。 This inputs have and id of 'NameInput' + X where x is a number generated (from 1 to 9 -- depending on the number of inputs). 此输入的ID为'NameInput'+ X,其中x是生成的数字(从1到9-取决于输入的数量)。 I'm using php and I want to select the one input that is visible. 我使用的是php,我想选择一个可见的输入。 I would use the id but each time the page is loaded, because of the random number each time the input's id visible is different. 我会使用id,但是每次加载页面时,由于每次输入的id可见的随机数都是不同的。 I've googled it and try to find a code that selects the id (first part of it that is the same for all inputs) and the display style. 我在Google上进行了搜索,并尝试找到一个选择ID(所有输入均相同的ID)和显示样式的代码。 Tried a lot of code snippets but no success. 尝试了很多代码段,但没有成功。 This is where I am now but i got this error. 这是我现在的位置,但出现此错误。

An invalid or illegal selector 无效或非法的选择器

$this->_webDriver->findElement(WebDriverBy::cssSelector('[id^=NameInput]:not[style=display:none]'))

Any help would be great! 任何帮助将是巨大的!

So this is what I ended up with: 这就是我最终得到的结果:

$nameInputs = $this->_webDriver->findElements(WebDriverBy::cssSelector('input[id^="NameInput"]'));
    foreach ($nameInputs as $name) {
        if($name->getCSSValue('display') === 'block') {
            $name->sendKeys('Jellos');

It might help someone! 它可能会帮助某人!

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

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