【问题标题】:Not able to click the image button using selenium web driver in C#无法在 C# 中使用 selenium Web 驱动程序单击图像按钮
【发布时间】:2015-03-02 12:14:59
【问题描述】:

我正在使用 selenium 自动化我的测试。我目前无法单击图像按钮。请看下面的代码

<input name="op-DPChoose-MAESTRO^SSL" type="image" src="/images/logos/MAESTRO.gif" alt="Maestro">

我正在使用下面的代码来识别元素并单击。

driver.FindElement(By.XPath("//img[@src ='/images/logos/MAESTRO.gif' and @alt='Maestro']")).Click();

不确定是什么问题。有人可以帮忙吗?

【问题讨论】:

    标签: c# selenium selenium-webdriver


    【解决方案1】:

    试试//input 而不是//img。除此之外,您的 XPath 应该没问题

    driver.FindElement(By.XPath("//input[@src ='/images/logos/MAESTRO.gif' and @alt='Maestro']")).Click();
    

    【讨论】:

    • 嗨 Vivek,我收到以下消息。没有这样的元素
    • @Tom 是您在 iFrame 中的输入吗?如果提供的 html 是正确的,那么我的答案中的 XPath 没有其他原因应该没有找到它
    • 是的,它在 iFrame 中
    • 查看这个有用的答案。您需要先切换到 iFrame stackoverflow.com/questions/14727617/…
    猜你喜欢
    • 1970-01-01
    • 2021-10-15
    • 2016-09-29
    • 2014-05-30
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 2017-10-21
    相关资源
    最近更新 更多