gpt4 book ai didi

javascript - 单击按钮但程序崩溃 selenium webdriver

转载 作者:行者123 更新时间:2023-12-02 15:21:29 25 4
gpt4 key购买 nike

<div class="post-info-tumblelogs">
<div class="post-info-post-tumblelog">
<div class="post-info-tumblelog">
<a class="follow_link worded-follow-button" data-subview="follow" href="/follow/iglovequotes">
<div class="follow-text" title="Follow">Follow</div>
<div class="unfollow-text" title="Unfollow">Unfollow</div>
</a>
</div>
</div>
</div>

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.manage().window().maximize();


driver.get('https://www.tumblr.com/login');
driver.findElement(webdriver.By.id('signup_email')).sendKeys('username');
driver.findElement(webdriver.By.id('signup_password')).sendKeys('password');
driver.findElement(webdriver.By.id('signup_forms_submit')).click();

driver.get('https://www.tumblr.com/search/tv+series');


/* THIS PART IS FOR FOLLOW
driver.wait(function(){
var followButton = driver.findElement(webdriver.By.xpath("/html/body/div[4]/div/div/div[2]/div[2]/div[1]/div[2]/div/article[3]/header/div/div/div/a/div[1][@class='follow-text']"));
followButton.click();
},3000);
*/

// THIS PART IS FOR LOVE BUTTON
driver.wait(function(){
var followButton = driver.findElement(webdriver.By.xpath("/html/body/div[4]/div/div/div[2]/div[2]/div[1]/div[2]/div/article[2]/div/div[2]/div/div[@class='post_control like']"));
followButton.click();
},3000);



driver.quit();

我使用 selenium webdriver 和 javascript。在此代码中,我尝试单击 tumblr 页面中的“关注”按钮和“喜欢”按钮,但单击该按钮后,出现错误并且不执行下一步操作,导致崩溃。关注和喜欢按钮的错误如下:

goog.global.setTimeout(function() { throw exception; }, 0);
^
NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div/div/div[2]/div[2]/div[1]/div[2]/div/article[2]/div/div[2]/div/div[@class='post_control like']"}

UnknownError: unknown error: Element is not clickable at point (934, 590). Other element would receive the click: <div class="unfollow-text" title="Unfollow">...</div>

第一个错误是关于爱情按钮,第二个错误是关于关注按钮。我可以做什么来解决这个问题?在这两个操作中,它都成功并单击了按钮,但该错误阻止我在同一代码中执行另一个操作。我正在等待您的帮助。

最佳答案

您正在使用绝对xpath

尝试这样的事情:-

driver.findElement(By.xpath("//div[@title='Unfollow']"));

如果您在此处发布了完整的 HTML 代码或页面链接,将会很有帮助,以便我们可以更准确地为您提供帮助。

希望对你有帮助:)

关于javascript - 单击按钮但程序崩溃 selenium webdriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34005655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com