selenium-webdriver 相关问题

Selenium-WebDriver提供WebDriver API,用于控制不同编程语言的浏览器(“语言绑定”)。使用此标记时,还要为正在使用的编程语言添加标记。

子C#设置默认下载目录使登录停止工作

如果我评论它设置选项的位置。登录正常工作。 当选项在那里时,它将等待所有300秒,并引发错误,说找不到元素。 当我看司机时。

回答 1 投票 0

发生:StaleelementReementReferencection pythonselenium

我遇到的错误是“发生了例外:StaleelementReferenceException 消息:过时的元素参考:在当前帧中找不到的陈旧元素“在行上抛出的text_arpend.append(div.get_attribute('innerhtml''))

回答 1 投票 0

解决该问题后,我可以提交hcaptcha 我正在尝试使用Python的硒自动登录自动化。在按下登录按钮之前,有一个需要解决的hCaptcha。到目前为止,我已经完成了此代码: def solve_captcha(self): 已解决= ...

def solve_captcha(self): solved = False api_key = os.getenv("TWO_CAPTCHA_APIKEY") solver = TwoCaptcha(api_key) code = None try: print("Solving captcha......") result = solver.hcaptcha( sitekey="ced407c5-238b-4144-9b59-4dcd58092d36", url="https://www.bakecaincontrii.com/u/login/" ) except Exception as e: print(e) else: solved = True code = result["code"] # sys.exit('solved: ' + str(result)) return str(code) def test(self, url_path): wait = WebDriverWait(self, 120) self.get(url_path) print("Url hit") print("going to next step......") time.sleep(3) # shake the mouse actions = ActionChains(self) num_of_shakes = 2 for _ in range(num_of_shakes): actions.move_by_offset(5, 5) actions.move_by_offset(-5, -5) actions.perform() time.sleep(2) # checking for the modal accept_cookie = wait.until( EC.visibility_of_element_located((By.XPATH, "//button[@class='btn btn-primary w-50 rounded-pill b1']"))) accept_cookie = wait.until(EC.element_to_be_clickable(( By.XPATH, "//button[@class='btn btn-primary w-50 rounded-pill b1']" ))) accept_cookie.click() time.sleep(3) # accept_cookie.click() # if accept_cookie.is_displayed(): # accept_cookie.click() print("check email field....") xpath_email = "//input[@placeholder='Email']" xpath_e_mail = "//input[@placeholder='E-mail']" email = wait.until(EC.element_to_be_clickable((By.XPATH, f"{xpath_email}|{xpath_e_mail}"))) print("email field found...") email.click() print("email field clicked") print("sending keys to email fields") email.send_keys("") time.sleep(3) # filling up the password password = wait.until(EC.element_to_be_clickable(( By.XPATH, "//input[@placeholder='Password']" ))) time.sleep(2) password.click() time.sleep(2) password.send_keys("") time.sleep(2) # cp = wait.until(EC.element_to_be_clickable( # (By.XPATH, '//*[@id="hcap-script"]/iframe') # )) # print("Captcha loaded") # time.sleep(3) # cp.click() # print("Captcha Clicked") solve_captcha = self.solve_captcha() print("code", solve_captcha) print("processing code to element") code = str(solve_captcha) print(type(code)) time.sleep(2) script = f"document.querySelector(" + "'" + '[name="h-captcha-response"]' + "'" + ").innerHTML = " + "'" + code + "'" # script = f'document.querySelector(\'input[name="h-captcha-response"]\').value = "{code}";' print(script) self.execute_script(script) print("now going to login") print("login button processing......") time.sleep(2) # login login_button = wait.until(EC.element_to_be_clickable(( By.XPATH, '//*[@id="app"]/main/div[2]/form/button' ))) login_button.click() time.sleep(2)

回答 1 投票 0

Why does ExecuteCdpCommand not work with WebDriver

We have a regression suite which we run on Chrome with code created in Visual Studio/C# and Selenium. Part of the startup code is shown below protected static ChromeDriver? Driver { get;放; } = n...

回答 1 投票 0

Python|硒|调整最小/最大值的价格滑块的值

目前我正在使用的代码是:

回答 1 投票 0



Py3.12硒scrape挂在Ubuntu上,但在Windows

我写了这位阅读房地产网络列表的网络刮板,但是由于某些奇怪的原因,当我在Ubuntu 24.02服务器上运行它时会失败,但可以在我的Win 10 Machine上使用。我在Python 3.12 ....

回答 1 投票 0

我如何检查以前缀开头的属性(不是属性值),并以后缀

1 <tr _ngcontent-hse-63=""> <td _ngcontent-hse-63=""> <span _ngcontent-hse-63="">1</span> </td> <td _ngcontent-hse-63=""> <span _ngcontent-hse-63="" class="noBr">CKH HOLDINGS</span> </td> </tr> 我有上述内容,我希望在硒中提取TD元素。但是,似乎NGCONTENT和数字之间的三个字母是随机的。我已经基于类似的问题尝试了以下问题:ref: By.xpath("//td[starts-with(@_ngcontent, '_ngcontent-') and ends-with(@_ngcontent, '-63')]"); 尽管@_ngcontent甚至不匹配任何属性,但我不太确定如何继续,我认为starting-with()和end-with()将与属性值匹配,而不是属性本身。 无论如何在那里解决这个问题吗?由于页面上还有很多其他元素,因此不可能使用TD元素。 BROWSER仅支持XPATH 1.0,不支持ends-with()。 您不能在硒中使用它。因此,您必须使用contains()您想通过以下XPath来实现您要做的事情。 //@*[starts-with(name(),'_ngcontent-') and contains(name(),'-63')]/parent::td iT选择具有以_ngcontent-并包含-63的属性的所有TD元素。

回答 1 投票 0

使用自定义用户数据目录

该代码是使用硒来爬网的代码,但是在更新Chrome和Chrome驱动程序后,.get()似乎无法正常工作。 Chrome版本是“ 133.0.6943.99”和Chrome Driver Versi ...

回答 1 投票 0

修改AngularJS页面的占位符字段后,不触发“保存”按钮 我正在使用Selenium + Python自动化网页,我需要更新邮政编码字段。 UI中的预期行为是: 最初隐藏了“保存”按钮。 当我单击...

最初隐藏了“保存”按钮。 当我单击邮政编码字段时,出现“保存”按钮,但仍将禁用。 当我键入某些内容时,“保存”按钮将变得可单击。 但是,当我尝试使用硒输入文本时,“保存”按钮永远不会出现或变得可单击。

回答 1 投票 0

seleenium python我如何预成式单击切换按钮

我正在尝试使用python上的Web Driver使用Selenium单击呼叫循环切换。 HTML代码: 这是按钮: 我尝试了一些选择: button_element =驱动程序.find_element_by_class_name(&

回答 3 投票 0



如何使用Python selenium

使用python selenium缩放ng点击表单按钮 我尝试从使用硒中提交一个,但是当我通过单击方法时,什么都不会发生 按钮html: 使用Python selenium缩放ng-click-click form按钮 我尝试从使用硒中提交一个,但是当我通过单击方法时,什么都不会发生 按钮html: <button type="submit" class="btn btn-default center-block btn-send col-sm-12" aria-label="כניסה לחשבון שלי" ng-click="vm.ResendNewLogin('password','login')" role="button" data-uw-rm-kbnav="role" tabindex="0"> <span ng-show="vm.isSubmitting" class="myLoader ng-hide"> <img src="/statics/img/ajax-loader-snake-tr.gif" height="18"> </span> <span ng-bind="vm.epiData.LoginButtonText" class="ng-binding">כניסה לחשבון שלי</span> </button> 在我的代码中,我尝试了几种方法,但没有任何可用 WebDriverWait(driver , 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="otpLobbyFormPassword"]/button'))).click() # Wait for the element with ng-click to be clickable ng_click_element = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="otpLobbyFormPassword"]/button')) ) ng_click_element.click() element = driver.find_element(By.XPATH,"//*[@aria-label='כניסה לחשבון שלי']").click() actions = ActionChains(driver) actions.move_to_element(element).click().perform() driver.quit() 单击在角元素上失败 角异步操作:ng-click通常会触发异步操作,即硒不会自动等待 element状态不匹配:该按钮可能在视觉上可单击,但具有隐藏的角绑定(例如,ng-disabled),在html中不可见 事件拦截:角有时会拦截本机硒点击 可兑现的解决方案 在确保Angular完成处理时,使用JavaScript直接执行Angular Click处理程序: from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Wait for Angular to stabilize driver.execute_async_script(""" var callback = arguments[arguments.length - 1]; if (window.angular) { angular.element(document.body).injector().get('$browser').notifyWhenNoOutstandingRequests(callback); } else { callback(); } """) # Use ARIA label for better reliability (unique accessibility attribute) button = WebDriverWait(driver, 20).until( EC.presence_of_element_located((By.CSS_SELECTOR, "button[aria-label='כניסה לחשבון שלי']")) ) javascript单击旁路webdriver的本机事件系统 driver.execute_script(“ gragments [0] .click();“,button) 键的增强功能 角度特定等待 execute_async_script等待Angular的出色HTTP请求和DOM更新完成。 CSS选择器优势 使用按钮[aria-label ='...']比xpath更稳定: 不容易变化dom层次结构 直接针对可访问性属性 javascript单击 绕过有时会因角元素而失败的Web Driver的本机点击机制。

回答 1 投票 0






最新问题
© www.soinside.com 2019 - 2025. All rights reserved.