相关疑难解决方法(0)

Selenium Webdriver在子元素中查找元素

我试图用Selenium(版本2.28.0)搜索子元素中的元素,但selenium des似乎没有将其搜索限制为子元素.我这样做错了还是有办法使用element.find来搜索子元素?

举个例子,我用这段代码创建了一个简单的测试网页:

<!DOCTYPE html>
<html>
    <body>
        <div class=div title=div1>
            <h1>My First Heading</h1>
            <p class='test'>My first paragraph.</p>
        </div>
        <div class=div title=div2>
            <h1>My Second Heading</h1>
            <p class='test'>My second paragraph.</p>
        </div>
        <div class=div title=div3>
            <h1>My Third Heading</h1>
            <p class='test'>My third paragraph.</p>
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的python(2.6版)代码如下所示:

from selenium import webdriver

driver = webdriver.Firefox()

# Open the test page with this instance of Firefox

# element2 gets the second division as a web element
element2 = driver.find_element_by_xpath("//div[@title='div2']")

# Search second division for a paragraph …
Run Code Online (Sandbox Code Playgroud)

python selenium xpath

52
推荐指数
3
解决办法
5万
查看次数

Selenium WebDriver StaleElementReferenceException

运行我的测试时出现此错误:org.openqa.selenium.StaleElementReferenceException:元素不再附加到DOM

关于如何解决上述异常的任何想法?这发生在我的网格中,它有一个动态的ref Xpath表达式

java testing selenium webdriver

25
推荐指数
2
解决办法
4万
查看次数

标签 统计

selenium ×2

java ×1

python ×1

testing ×1

webdriver ×1

xpath ×1