首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >注册:安全证书上的WebDriver

注册:安全证书上的WebDriver
EN

Stack Overflow用户
提问于 2011-09-08 01:39:02
回答 2查看 2.8K关注 0票数 1

我在过去的6个月里一直在使用WebDriver。

我现在面临着几个问题,版本2.3.1

a)当我尝试通过webdriver findElement在IE的安全证书https页面上获取覆盖链接的元素时,它无法找到该元素,但selenium RC工作正常。

然后,我通过使用以下命令获得了tht的修复: webDriver.navigate().to(javascript:document.getElementById('overridelink').click());

注意:我尝试使用下面的代码来获取安全证书页面上的元素,但是它返回了body元素

带有焦点的WebElement activeElement() WebElement,或者如果没有检测到带有焦点的元素,则为正文元素。为什么不能使用findelement来挑选元素?

b)我通过SSL连接远程网络以运行webdriver测试,无法单击安全证书https页面上的override链接?

c)实现webdriver的更好的方法是直接使用它而不是使用jbehave这样的框架吗?

请提供您的建议谢谢,Jayaraj A

EN

回答 2

Stack Overflow用户

发布于 2011-12-01 00:22:25

感谢您的变通!

对于Java,您的解决方案看起来有点不同,这对我很有帮助:

代码语言:javascript
复制
//driver is initialised somewhere before, for example, as RemoteWebDriver     
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
票数 2
EN

Stack Overflow用户

发布于 2011-11-24 08:30:59

是啊,我也有过类似的问题。Webdriver似乎没有完整的信息

由于某种原因导致的证书错误页面。

我在Windows XP SP3上,使用Python/Webdriver运行IE7

我正在使用这个黑客来绕过证书错误页面:

(帮助,我仍然不能获得自由的Markdown来格式化代码块...)

代码语言:javascript
复制
#!/c/Python27/python

import win32con
import win32gui

def certificate_continue():
    """
    Find the IE Window that has a Certificate Error and try to continue anyway.
    We'll use the win32 modules to find the right window & child window,
    then write some Javascript into the address bar and execute to continue.
    """
    def _enumWindowsCallback(hwnd, windows):
        """
        Cannibalized from Gigi Sayfan (WindowMover)
        http://www.devx.com/opensource/Article/37773/1954
        This appends window information as a 3-tuple to the list
        passed into win32gui.EnumWindows()
        """
        class_name = win32gui.GetClassName(hwnd)
        # apparently win32gui.GetWindowText() only works to get the text
        # on a button or a label not really for edit windows.
        text = win32gui.GetWindowText(hwnd)
        windows.append((hwnd, class_name, text))


    def _get_certificate_error_window():
        """
        all_windows[] gets filled up with a list of tuples, then loop through
        it filtering on class and the window text (title bar text).
        Assumes only one 'Certificate Error' window.
        """
        all_windows = []
        win32gui.EnumWindows(_enumWindowsCallback, all_windows)
        for win in all_windows:
            class_name = win[1]
            title_bar_text = win[2]
            if class_name == 'IEFrame' and \
                     'Certificate Error: Navigation Blocked' in title_bar_text:
                return win

    def _get_edit_text(hwnd):
        """
        This function courtesy of Omar Raviv with huge help from Simon Brunning.
        http://www.brunningonline.net/simon/blog/archives/000664.html
        """
        buf_size = win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0)
        buf_size += 1 # don't forget that null character boys...
        buffer = win32gui.PyMakeBuffer(buf_size)
        # odd, we're telling them how big the text is that they're giving
        # back to us
        win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buf_size, buffer)
        # don't need the null character now for Python
        return buffer[:buf_size]


    def _get_address_bar(parent_handle):
        """
        There appears to be several 'Edit' windows within each browser window.
        From Microsoft: If a child window has created child windows of its own,
        EnumChildWindows enumerates those windows as well.
        """
        childwins = []
        win32gui.EnumChildWindows(parent_handle, _enumWindowsCallback,
                                  childwins)
        for win in childwins:
            child_handle = win[0]
            class_name = win[1]
            if 'Edit' in class_name:
                edit_text = _get_edit_text(child_handle)
                if 'http://' in edit_text or 'https://' in edit_text:
                    return child_handle  # then this must be it...


# begin certificate_continue
    target_win = _get_certificate_error_window()
    try:
        cert_err_handle = target_win[0]
    except TypeError:
        print "OK, no Certificate Error window available"
        return(1)

    address_bar_handle = _get_address_bar(cert_err_handle)
    # any better way to check the handle ?
    if not win32gui.IsWindow( address_bar_handle):
        print "Choked getting IE edit window"
        return(1)

    # now, need to send this JavaScript text to the browser Address Bar
    javascript_continue = 'javascript: var continue_element = document.getElementById("overridelink"); continue_element.click();'
    win32gui.SendMessage(address_bar_handle, win32con.WM_SETTEXT, 0,
                         javascript_continue)

    # OK, and finally, send a carriage return to the address bar
    # This last abomination, courtesy of Claudiu
    # http://stackoverflow.com/#questions/5080777/
    # what-sendmessage-to-use-to-send-keys-directly-to-another-window
    win32gui.SendMessage(address_bar_handle, win32con.WM_KEYDOWN,
                         win32con.VK_RETURN, 0)
    return(0)


if __name__ == '__main__':
    status = certificate_continue()
    exit(status)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7338128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档