<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Selenium &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Tue, 25 Aug 2020 07:53:46 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] selenium-java的wait.until(ExpectedConditions)编译出错问题</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-selenium-java%e7%9a%84wait-untilexpectedconditions%e7%bc%96%e8%af%91%e5%87%ba%e9%94%99%e9%97%ae%e9%a2%98/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-selenium-java%e7%9a%84wait-untilexpectedconditions%e7%bc%96%e8%af%91%e5%87%ba%e9%94%99%e9%97%ae%e9%a2%98/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Tue, 25 Aug 2020 07:52:47 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ExpectedConditions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Selenium]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=12876</guid>

					<description><![CDATA[<p>代码示例：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">wait.until(ExpectedConditions.alertIsPresent());
Alert&#160;alert&#160;=&#160;driver.switchTo().alert();
alert.accept();
</code></pre>
</section>
<p>在升级了pom.xml中的selenium-java版本到3.141.59后，代码编译出错了（挂在第一行），错误信息：</p>
<blockquote>
<div>
		无法将类 org.openqa.selenium.support.ui.FluentWait&#60;T&#62;中的方法 until应用到给定类型;</div>
<div>
		[ERROR]&#160; &#160;需要: java.util.function.Function&#60;? super org.openqa.selenium.WebDriver,V&#62;</div>
<div>
		[ERROR]&#160; &#160;找到: org.openqa.selenium.support.ui.ExpectedCondition&#60;org.openqa.selenium.Alert&#62;</div>
<div>
		[ERROR]&#160; &#160;原因: 无法推断类型变量 V</div>
<div>
		[ERROR]&#160; &#160; &#160;(参数不匹配; org.openqa.selenium.support.ui.ExpectedCondition&#60;org.openqa.selenium.Alert&#62;无法转换为java.util.function.Function&#60;? super org.openqa.selenium.WebDriver,V&#62;)</div>
</blockquote>
<div>
<span id="more-12876"></span>	<br />
	原因：pom.xml里如下依赖版本太低：
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&#62;</span>com.google.guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&#62;</span>guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&#62;</span>19.0<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&#62;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&#62;</span></code></pre>
</section>
<p>
	改成：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&#62;</span>
&#160;&#160;&#160;&#160;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&#60;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&#62;</span>com.google.guava</code></pre></section></div>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-selenium-java%e7%9a%84wait-untilexpectedconditions%e7%bc%96%e8%af%91%e5%87%ba%e9%94%99%e9%97%ae%e9%a2%98/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>代码示例：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="java language-java hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;">wait.until(ExpectedConditions.alertIsPresent());
Alert&nbsp;alert&nbsp;=&nbsp;driver.switchTo().alert();
alert.accept();
</code></pre>
</section>
<p>在升级了pom.xml中的selenium-java版本到3.141.59后，代码编译出错了（挂在第一行），错误信息：</p>
<blockquote>
<div>
		无法将类 org.openqa.selenium.support.ui.FluentWait&lt;T&gt;中的方法 until应用到给定类型;</div>
<div>
		[ERROR]&nbsp; &nbsp;需要: java.util.function.Function&lt;? super org.openqa.selenium.WebDriver,V&gt;</div>
<div>
		[ERROR]&nbsp; &nbsp;找到: org.openqa.selenium.support.ui.ExpectedCondition&lt;org.openqa.selenium.Alert&gt;</div>
<div>
		[ERROR]&nbsp; &nbsp;原因: 无法推断类型变量 V</div>
<div>
		[ERROR]&nbsp; &nbsp; &nbsp;(参数不匹配; org.openqa.selenium.support.ui.ExpectedCondition&lt;org.openqa.selenium.Alert&gt;无法转换为java.util.function.Function&lt;? super org.openqa.selenium.WebDriver,V&gt;)</div>
</blockquote>
<div>
<span id="more-12876"></span>	<br />
	原因：pom.xml里如下依赖版本太低：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>com.google.guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>19.0<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span></code></pre>
</section>
<p>
	改成：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="xml language-xml hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>com.google.guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">groupId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>guava<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">artifactId</span>&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>21.0<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">version</span>&gt;</span>
<span class="hljs-tag" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">&lt;/<span class="hljs-name" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">dependency</span>&gt;</span></code></pre>
</section>
<p>即可解决问题。</p></div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-selenium-java%e7%9a%84wait-untilexpectedconditions%e7%bc%96%e8%af%91%e5%87%ba%e9%94%99%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[原创] 解决Selenium的&quot;failed to change window state to maximized&quot; 窗口最大化问题</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3selenium%e7%9a%84failed-to-change-window-state-to-maximized-%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%8c%96%e9%97%ae%e9%a2%98/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3selenium%e7%9a%84failed-to-change-window-state-to-maximized-%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%8c%96%e9%97%ae%e9%a2%98/#comments</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 23 Oct 2017 09:16:51 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[failed to change window state to maximized]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[最大化窗口]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=9937</guid>

					<description><![CDATA[<p>
<span style="color:#0000ff;">OS</span>：Ubuntu 16.04.3 LTS<br />
<span style="color:#0000ff;">JDK</span>：1.8.0_60<br />
<span style="color:#0000ff;">Selenium</span>：3.0.0<br />
<span style="color:#0000ff;">Chrome</span>：61.0.3163.100</p>
<p>本文描述了用JAVA编程控制Selenium时，遇到的&#8220;<span style="color:#ff0000;">failed to change window state to maximized, current state is normal</span>&#8221;错误的解决方法。<br />
<span id="more-9937"></span><br />
在一些自动化任务中，最大化浏览器窗口是一个非常频繁使用的功能，如果你用了&#160;<span style="color:#b22222;">driver.manage().window().maximize()</span> 这个方法来最大化浏览器窗口的话，有很大的机会遇到以下问题：</p>
<blockquote>
<div>
		Exception in thread &#34;main&#34; org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal</div>
<div>
		&#160; (Session info: chrome=61.0.3163.100)</div>
<div>
		&#160; (Driver info: chromedriver=2.30,platform=Linux 4.10.0-37-generic x86_64) (WARNING: The server did not provide any stacktrace information)</div>
<div>
		Command duration or timeout: 818 milliseconds</div>
<div>
		Build info: version: &#39;unknown&#39;, revision: &#39;unknown&#39;, time: &#39;unknown&#39;</div>
<div>
		System info: host: &#39;codelast&#39;, ip: &#39;127.0.1.1&#39;, os.name:</div></blockquote>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3selenium%e7%9a%84failed-to-change-window-state-to-maximized-%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%8c%96%e9%97%ae%e9%a2%98/" class="read-more">Read More </a>]]></description>
										<content:encoded><![CDATA[<p>
<span style="color:#0000ff;">OS</span>：Ubuntu 16.04.3 LTS<br />
<span style="color:#0000ff;">JDK</span>：1.8.0_60<br />
<span style="color:#0000ff;">Selenium</span>：3.0.0<br />
<span style="color:#0000ff;">Chrome</span>：61.0.3163.100</p>
<p>本文描述了用JAVA编程控制Selenium时，遇到的&ldquo;<span style="color:#ff0000;">failed to change window state to maximized, current state is normal</span>&rdquo;错误的解决方法。<br />
<span id="more-9937"></span><br />
在一些自动化任务中，最大化浏览器窗口是一个非常频繁使用的功能，如果你用了&nbsp;<span style="color:#b22222;">driver.manage().window().maximize()</span> 这个方法来最大化浏览器窗口的话，有很大的机会遇到以下问题：</p>
<blockquote>
<div>
		Exception in thread &quot;main&quot; org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal</div>
<div>
		&nbsp; (Session info: chrome=61.0.3163.100)</div>
<div>
		&nbsp; (Driver info: chromedriver=2.30,platform=Linux 4.10.0-37-generic x86_64) (WARNING: The server did not provide any stacktrace information)</div>
<div>
		Command duration or timeout: 818 milliseconds</div>
<div>
		Build info: version: &#39;unknown&#39;, revision: &#39;unknown&#39;, time: &#39;unknown&#39;</div>
<div>
		System info: host: &#39;codelast&#39;, ip: &#39;127.0.1.1&#39;, os.name: &#39;Linux&#39;, os.arch: &#39;amd64&#39;, os.version: &#39;4.10.0-37-generic&#39;, java.version: &#39;1.8.0_60&#39;</div>
<div>
		Driver info: org.openqa.selenium.chrome.ChromeDriver</div>
<div>
		Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30, userDataDir=/tmp/.org.chromium.Chromium.uMCzgg}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=61.0.3163.100, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]</div>
<div>
		Session ID: 0f4ef7760fd6071f5aa9d31b98001663</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.reflect.Constructor.newInstance(Constructor.java:422)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)</div>
<div>
		&nbsp; &nbsp; &nbsp; &nbsp; at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:882)<br />
		......<br />
		&nbsp;</div>
</blockquote>
<p>结果当然就是程序跑挂了。<br />
这不是你的程序写的错，而是Selenium的一个bug。无数人都在各种网站反馈了这个问题，例如<a href="https://github.com/SeleniumHQ/docker-selenium/issues/559" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这里</span></a>，<a href="https://bugs.chromium.org/p/chromedriver/issues/detail?id=1901" target="_blank" rel="noopener noreferrer"><span style="background-color:#ffa07a;">这里</span></a>，等等。而且貌似Selenium的开发者们暂时不打算修复这个问题，因为有人发现了一些变通方案来实现浏览器窗口最大化，并且验证了不会出现上面的问题。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
我这里的情况是，如下代码是有问题的：</p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
<span style="color: rgb(255, 238, 128);">System</span><span style="color: rgb(255, 157, 0);">.</span>setProperty<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(58, 217, 0);">&quot;</span>webdriver.chrome.driver<span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(225, 239, 255);">,</span> <span style="color: rgb(58, 217, 0);">&quot;</span>/usr/lib/chromium-browser/chromedriver<span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(225, 239, 255);">;</span>
    <span style="color: rgb(255, 238, 128);">WebDriver</span> driver <span style="color: rgb(255, 157, 0);">=</span> <span style="color: rgb(255, 157, 0);">new</span> <span style="color: rgb(255, 238, 128);">ChromeDriver</span>()<span style="color: rgb(225, 239, 255);">;</span>
    driver<span style="color: rgb(255, 157, 0);">.</span>manage<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(255, 157, 0);">.</span>window<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(255, 157, 0);">.</span>maximize<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(225, 239, 255);">;</span>    <span style="color: rgb(0, 136, 255); font-style: italic;"><span style="color: rgb(225, 239, 255);">//</span> maximize the browser window when it starts</span></pre>
<p>这几乎肯定会触发上面所说的问题，只有运气好的少数几次不会挂。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" target="_blank" rel="noopener noreferrer"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
解决办法如下：</p>
<pre style="margin-top: 0px; margin-bottom: 0px; font-stretch: normal; font-size: 0.9333em; line-height: 1.5em; font-family: Consolas, &quot;Lucida Console&quot;, &quot;DejaVu Sans Mono&quot;, Monaco, &quot;Courier New&quot;, monospace; background: rgb(0, 34, 64); color: rgb(255, 255, 255);">
    <span style="color: rgb(255, 238, 128);">System</span><span style="color: rgb(255, 157, 0);">.</span>setProperty<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(58, 217, 0);">&quot;</span>webdriver.chrome.driver<span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(225, 239, 255);">,</span> <span style="color: rgb(58, 217, 0);">&quot;</span>/usr/lib/chromium-browser/chromedriver<span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(225, 239, 255);">;</span>
    <span style="color: rgb(255, 238, 128);">ChromeOptions</span> options <span style="color: rgb(255, 157, 0);">=</span> <span style="color: rgb(255, 157, 0);">new</span> <span style="color: rgb(255, 238, 128);">ChromeOptions</span>()<span style="color: rgb(225, 239, 255);">;</span>
    options<span style="color: rgb(255, 157, 0);">.</span>addArguments<span style="color: rgb(225, 239, 255);">(</span><span style="color: rgb(58, 217, 0);">&quot;</span>start-maximized<span style="color: rgb(58, 217, 0);">&quot;</span><span style="color: rgb(225, 239, 255);">)</span><span style="color: rgb(225, 239, 255);">;</span>
    <span style="color: rgb(255, 238, 128);">WebDriver</span> driver <span style="color: rgb(255, 157, 0);">=</span> <span style="color: rgb(255, 157, 0);">new</span> <span style="color: rgb(255, 238, 128);">ChromeDriver</span>(options)<span style="color: rgb(225, 239, 255);">;</span></pre>
<p>经实际观察，几乎没有再出现上面的问题。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e8%a7%a3%e5%86%b3selenium%e7%9a%84failed-to-change-window-state-to-maximized-%e7%aa%97%e5%8f%a3%e6%9c%80%e5%a4%a7%e5%8c%96%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
