1

我正在尝试填写多个表单,所有表单都会快速填写,没有错误,因为我确保添加

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("")));

在新页面上做任何事情之前,我知道我在正确的页面上。

在最后一个表单上,我遇到了这个错误:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id="formtovalidate"]/fieldset[1]/div/label/input For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

所以我通过截屏检查浏览器,浏览器位于正确的页面上,格式正确,我还检查了 xpath 值,甚至尝试了其他属性.. 似乎没有任何效果。

所以我继续打印出显示完全不同页面(不是上一页)的 PageSource,我还注意到在最终表单出现之前,此页面闪烁了一秒钟。

我也试过driver.navigate().refresh(),但没有奏效。我一直在寻找和寻找,但什么都没有出现。我也换了浏览器,什么也没做。。

这是我试图执行的方法:

private void method() {

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"formtovalidate\"]/fieldset[1]/div/label/input")));
driver.findElement(By.xpath("//*[@id=\"formtovalidate\"]/fieldset[1]/div/label/input")).sendKeys(email); }

更新

这是表单截图:

以下是执行结果:

代码:

String body_text = driver.findElement(By.tagName("body")).getText();
System.out.println(body_text);

结果:表格但在文本中

代码:

String body_innerHTML = driver.findElement(By.tagName("body")).getAttribute("innerHTML");
System.out.println(body_innerHTML);

结果:不同的页面:(

<zendesk-ticketing-form base-url="https://www.runescape.com/a=870/c=K0aO9WO69EI" css-cachebust="129" sitekey="6Lcsv3oUAAAAAGFhlKrkRb029OHio098bbeyi_Hv" grecaptcha="" has-valid-session="true" weblogin-url="https://secure.runescape.com/m=weblogin/a=870/c=K0aO9WO69EI/loginform?mod=www&amp;ssl=1&amp;dest=zendesk/support-form?form=360000065898">
<div class="x-display-none ie-error-display" data-js-ie-error="">
    <section class="c-article">
        <div class="c-article__content">
            <h1>Error: Unsupported Browser</h1>
            <p>
                We do not support your web browser. Please use a supported web browser by choosing one below.
                <br>
                <a href="https://www.mozilla.org/firefox/" target="_blank" rel="noopener">FireFox</a>
                <br>
                <a href="https://www.google.com/chrome/" target="_blank" rel="noopener">Chrome</a>
            </p>
        </div>
    </section>
</div>

代码:

 String pagesource = driver.getPageSource();
        System.out.println(pagesource);

结果:与上一个相同..不同的页面..

火狐页面来源:https ://pastebin.com/Kv15V2SK

Firefox Inspect Element 页面截图: http: //prntscr.com/qvi6hc

这很奇怪,因为页面源与表单不同!

4

3 回答 3

1

来自标签的PageSource<body>,包含...

<zendesk-ticketing-form base-url="https://www.runescape.com/a=870/c=K0aO9WO69EI" css-cachebust="129" sitekey="6Lcsv3oUAAAAAGFhlKrkRb029OHio098bbeyi_Hv" grecaptcha="" has-valid-session="true" weblogin-url="https://secure.runescape.com/m=weblogin/a=870/c=K0aO9WO69EI/loginform?mod=www&amp;ssl=1&amp;dest=zendesk/support-form?form=360000065898">
<div class="x-display-none ie-error-display" data-js-ie-error="">
    <section class="c-article">
    <div class="c-article__content">
        <h1>Error: Unsupported Browser</h1>
        <p>
        We do not support your web browser. Please use a supported web browser by choosing one below.
        <br>
        <a href="https://www.mozilla.org/firefox/" target="_blank" rel="noopener">FireFox</a>
        <br>
        <a href="https://www.google.com/chrome/" target="_blank" rel="noopener">Chrome</a>
        </p>
    </div>
    </section>
</div>

...意味着WebDriver驱动的浏览上下文被检测为BOT,并且由于存在reCAPTCHA而导致导航被阻止。

有不同的方法来解决验证/重新。您可以在以下位置找到一些相关的讨论:


更新

现在从您的评论中可以清楚地看出您要填写表格中的字段:

形式

在这一点上,值得一提的是,由于以下任一原因,您已被重定向到此页面:

  • You EmailID / UserID is banned / blocked from accessing the site.
  • You EmailID / UserID is black-listed from accessing the site.

As you have used a BOT to access/scrape the site which may have violated the T&C.


Solution

It would be tough to propose a solution to automatically fillup the fields as presumably the elements in the BAN APPEAL REQUEST page may be protected by Invisible reCAPTCHA and you may have to Programmatically invoke the challenge

于 2020-01-31T10:40:11.570 回答
1

我找不到时间来解决你的问题。如果你想自己做,请在谷歌上搜索,“Shadow Root,Selenium”,我之前遇到过这种错误。我所知道的是,您无法直接访问位于影子根内部的元素,这就是为什么您没有获取其中的源代码的原因。

您需要做的是逐步完成元素:

你必须扩展影子根,

这是影子根扩展功能:

public static WebElement expand_shadow_element(WebElement element)
    {
        WebElement shadow_root = (WebElement)((JavascriptExecutor)driver).executeScript("return arguments[0].shadowRoot", element);
        return shadow_root;
    }

你可以把这个功能想象成

.switchTo.frame()

目前..

经过一些研究,您将了解影子根。

我希望我的问题是正确的..

试试这个功能,如果你不能,我稍后会帮助你。祝你好运。

于 2020-02-01T03:24:22.263 回答
0

As others have suggested, it appears RuneScape's website has detected that you're using a bot to interact with their site. It doesn't matter that you solved the captcha manually, as they can still detect automated behavior quite easily without one (and no, the navigator.webdriver flag is not their only way to detect this).

The captcha is meant to prevent automated interaction with their site, which means they don't want you using Selenium/WebDriver to interact with it. You should respect this, especially as it seems you want your account unbanned (going by the pasted snippets and screenshots), so trying to do exactly what they don't want won't win you any favors.

于 2020-01-31T12:23:18.600 回答