Tab Key Disabled in Embedded Browser

3 次查看(过去 30 天)
I've implemented a simple test version of the documentation example showing how to use Internet Explorer in a Matlab figure ( found here ). However, it appears that the tab key (e.g., used for movement between form fields) is disabled. Anyone know how to allow for movement across the loaded web page components via the tab key?
function hExp = testActiveX()
hFig = figure('Pos', [0 0 1280 1024], 'Menu', 'none', 'Name', 'ActiveX Testing', 'ResizeFcn', @reSize, 'Renderer', 'Opengl');
conSize = calcSize;
hExp = actxcontrol('Shell.Explorer.2', conSize, hFig);
Navigate(hExp, 'https://www.mathworks.com/login');
movegui(hFig, 'center');
% Determine size of control container
function conSize = calcSize()
fp = get(hFig, 'Pos');
conSize = [0 0 1 1] .* fp([3 4 3 4]);
end % calcSize()
% Figure resize callback
function reSize(~, ~)
if ~exist('hExp', 'var')
return;
end
conSize = calcSize;
move(hExp, conSize);
end % reSize()
end % testActiveX()

采纳的回答

H.A. Camp
H.A. Camp 2017-9-22
So, after consulting with MathWorks (thank you!) it appears that this is a known problem in working with ActiveX webBrowser components (and not just in Matlab). Currently, there is no native Matlab solution. However, Yair Altman's ever-helpful Undocumented Matlab site provides a workaround using Java.
While this overcomes the tab key limitations, my hang-up in using this solution has been my own ignorance in accessing web components (e.g., a text box, etc.) via code. But, as long as one is using R2015a or later, it turns out that this is relatively straight-forward:
% Create figure
fig = figure('Pos', [0 0 1280 1024], 'Name', 'Browser Test', 'Units', 'norm', 'Menu', 'none');
movegui(fig, 'center');
% Add Browser object
jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel;
[browserPanel, container] = javacomponent(jObject, [], fig);
set(container, 'Units', 'norm', 'Pos', [0,0,1,1]);
% Navigate to a URL
browserPanel.setCurrentLocation('https://www.mathworks.com/login');
% Get JxBrowser BrowserView and Browser objects
if verLessThan('matlab', '8.6')
error('JxBrowser BrowserView is not available in MATLAB R2015a or earlier');
elseif verLessThan('matlab', '9.1')
browserView = browserPanel.getComponent(0).getComponent(0).getComponent(0).getComponent(0);
else
browserView = browserPanel.getComponent(0).getComponent(0).getComponent(0);
end
browser = browserView.getBrowser();
% Wait until browser finishes loading
while browser.isLoading
pause(0.1);
end
% The login form is in a frame on this page. The frame id with the login form is 4
frameDocument = browser.getDocument(4);
% Example: Get the "userId" field and fill it with the text "testId"
userId = [];
while isempty(userId)
% It is possible that the content of the embedded frame has not
% finished loading yet. This loop will ensure that we wait until it
% finishes loading the userId field.
userId = frameDocument.findElement(com.teamdev.jxbrowser.chromium.dom.By.id('userId'));
pause(0.1);
end
userId.setValue('testId');
% Example: Get submit button and click it
submit = frameDocument.findElement(com.teamdev.jxbrowser.chromium.dom.By.id('submit'));
%submit.click(); % commented out because this is not a valid login
(This isn't my genius; I credit the MathWorks support team for helping to point me on the right path...)
  1 个评论
Yair Altman
Yair Altman 2017-9-24
It's very nice and user-friendly of MathWorks to point you to my blog. If you think about it, this is not obvious at all...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by