擅长:python、mysql、java
<p>阅读代码中的注释,了解代码不起作用的原因。<br/>
基本上,您正在尝试选择iframe中存在的东西。你知道吗</p>
<pre class="lang-py prettyprint-override"><code>option = webdriver.ChromeOptions()
option.add_argument(" incognito")
browser = webdriver.Chrome(executable_path='/Users/grsanchez/downloads/chromedriverM',
options=option)
browser.get('http://ptvtelecom.com/')
## finding the button that shows the form
btn = browser.find_element_by_css_selector('#cobertura .boton-cobertura')
## using js to click it, to avoid getting issues in case the button wasn't visible
driver.execute_script("arguments[0].click();", btn)
## the element you want to select is actually inside an iframe, so we need to switch to it, if we want to select anything
driver.switch_to.frame(driver.find_element_by_css_selector('#popmake-1432 iframe'));
## selecting the name input and sending a string
name = driver.find_element_by_css_selector('#nombre')
name.send_keys('user1')
</code></pre>
<p><strong>PS</strong>要返回主框架,可以执行以下操作:</p>
<pre class="lang-py prettyprint-override"><code>driver.switch_to.default_content()
</code></pre>