您的位置:

如何为AccessibilityService增强网站可访问性

一、使页面语义化

语义化的网页可以提高网站可用性和可访问性,对于 AccessibilityService(以下简称AS)也是同样适用。在语义化的网站上,AS 更容易理解网页中不同元素的作用,进而更准确地模拟用户行为。常见的语义化标签包括标题标签(<h1>~<h6>)、段落标签(<p>)、链接标签(<a>)等。

举个例子,假设我们模拟一个页面点击按钮的操作。如果按钮没有使用语义化标签,而是使用了<div>等容器标签,AS 就很难判断这个按钮是否具有点击事件,容易造成操作失败。因此,我们应该尽量使用语义化标签,减少使用无意义的标签。

<!-- 不推荐使用 --> 
<div onclick="alert('点击了按钮')">点击我</div>

<!-- 推荐使用 --> 
<button onclick="alert('点击了按钮')">点击我</button>

二、为元素添加描述性信息

有些元素在网页中可能没有明确的作用,或者需要更详细的描述信息,比如图片元素。在这种情况下,我们可以为元素添加描述性信息,方便 AS 更好地理解网页结构。常见的描述性信息包括 alt 文本、title 属性等。

以图片元素为例,如果没有 alt 属性或 alt 文本为空,AS 就无法知道这个图片元素的作用,只会按照默认的方式处理,可能会给用户带来不良体验。因此,我们应该为图片元素添加明确的 alt 文本,以便 AS 更好地模拟用户行为。

<!-- 错误示范 --> 
<img src="example.jpg">

<!-- 正确示范 --> 
<img src="example.jpg" alt="这是一张示例图片">

三、增加交互按钮

有些网页需要用户进行交互才能实现操作,比如弹出框和下拉框等。这种情况下,我们应该为页面增加交互按钮,以便 AS 更准确地模拟用户操作。常见的交互按钮包括确认按钮、取消按钮、下一步按钮等。

举个例子,假设我们需要点击弹出框中的确定按钮,如果没有对应的交互按钮,AS 就无法执行该操作。因此,我们应该为页面增加明确的交互按钮,以便 AS 更好地进行模拟点击操作。

<!-- 错误示范 --> 
<div class="popup">
    <p>确定要删除吗?</p>
</div>

<!-- 正确示范 --> 
<div class="popup">
    <p>确定要删除吗?</p>
    <button class="confirm">确定</button>
    <button class="cancel">取消</button>
</div>

四、提高网站响应速度

网站响应速度对于 AS 来说非常关键,它直接影响了 AS 执行操作的效率和准确性。我们可以通过优化代码、压缩文件等方式提高网站响应速度,从而提高 AS 的工作效率。

常见的优化方式包括缓存资源、删除不必要的代码、使用压缩文件等。另外,我们也可以采用异步加载的方式,将一些不必要的资源延迟加载,减少对网站响应速度的影响。

// 优化前
<script src="jquery.min.js"></script>
<script src="example.js"></script>

// 优化后
<script src="jquery.min.js"></script>
<script src="example.min.js"></script>
如何为AccessibilityService增强网站可访问

2023-05-18
Android AccessibilityService:使

2023-05-14
Android AccessibilityService详解

2023-05-20
提高Android应用可访问性的重要性与无障碍服务的实现方法

2023-05-14
CSS outline:如何使用CSS outline增强网

一、 CSS outline介绍 CSS outline是一个简单但非常实用的CSS属性,它可以为任何HTML元素添加一个可见的边框,不影响元素实际尺寸和位置。它与border属性非常相似,但是它的实

2023-12-08
如何更改like3icu地址,提高网站可访问性

2023-05-23
when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: ${item.id} [in template "article/detail/index.ftl" at line 48, column 106] ---- Java stack trace (for programmers): ---- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:481) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:401) at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:370) at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:104) at freemarker.core.DollarVariable.accept(DollarVariable.java:63) at freemarker.core.Environment.visit(Environment.java:371) at freemarker.core.IteratorBlock$IterationContext.executedNestedContentForCollOrSeqListing(IteratorBlock.java:321) at freemarker.core.IteratorBlock$IterationContext.executeNestedContent(IteratorBlock.java:271) at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:244) at freemarker.core.Environment.visitIteratorBlock(Environment.java:645) at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:108) at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94) at freemarker.core.Environment.visit(Environment.java:335) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.visit(Environment.java:341) at freemarker.core.Environment.process(Environment.java:314) at freemarker.template.Template.process(Template.java:383) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:332) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:266) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:220) at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:181) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1431) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1106) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at com.software.filter.HttpSpiderIdentifyFilter.doFilter(HttpSpiderIdentifyFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at java.base/java.lang.VirtualThread.run(VirtualThread.java:309)