无法在Selenium Python Webdriver中使用xpath定位html元素

时间:2019-07-01 19:37:05

标签: python-3.x selenium selenium-webdriver xpath python-behave

在我的html页面中,我想单击标签值为“ SIM卡”的元素。 但是isung xpath我找不到它。在SO中,我发现常见的问题是1. if元素在iframe中,在我的情况下不是。 2.等待元素可见。我正在等待一分钟,我可以在10秒内看到页面已完全加载。一分钟后,我还转储了整个outerHTML,可以看到其中的元素。因此,我相信这不是问题。谁能说出这里出了什么问题?

 <box-type-selection>
                                             <!----><!----><!---->
  <div data-input-field="">
<toggle-buttons data-labelprefix="PAGE.SELECT_SIM.SIM_TYPE." data-name="sim-type" _nghost-mhn-c16="">
<div _ngcontent-mhn-c16="" class="toggle-button-group toggle-button-group--centered validate ">
<!----><!----><input _ngcontent-mhn-c16="" tabindex="1" type="radio" name="sim-type" data-test-selector="sim-type-toggle-SIM_CARD" id="sim-type-toggle-0"><label _ngcontent-mhn-c16="" class="toggle-button__label" for="sim-type-toggle-0" data-test-selector="sim-type-toggle-SIM_CARD-label"> SIM card </label><!----><input _ngcontent-mhn-c16="" tabindex="1" type="radio" name="sim-type" data-test-selector="sim-type-toggle-ESIM_PROFILE" id="sim-type-toggle-1"><label _ngcontent-mhn-c16="" class="toggle-button__label" for="sim-type-toggle-1" data-test-selector="sim-type-toggle-ESIM_PROFILE-label"> eSIM profile </label>
</div>
 <!---->
</toggle-buttons>
</div>
<!---->
</box-type-selection>

我的代码-

WebDriverWait(context_browser, 60).until(EC.visibility_of_element_located((By.XPATH, '//div[@data-input-field=""]/toggle-buttons[@data-labelprefix="PAGE.SELECT_SIM.SIM_TYPE."]/div[@class="toggle-button-group toggle-button-group--centered validate "]/input[@id="sim-type-toggle-0"]'))).click()

我的代码中出现了selenium.common.exceptions.TimeoutException。

0 个答案:

没有答案