点(x,y)处无法点击元素

时间:2016-08-03 12:37:08

标签: java selenium

我有以下例外:

  

org.openqa.selenium.WebDriverException:元素无法点击   point(1057.38330078125,673.13330078125)。其他元素将收到   点击:

     

button id =“ID4b6a687af6934e35b6f355f6305dc481”   data-layout =“hbox”class =“hux-ui-button”type =“button”   角色= “按钮” >

enter image description here

如您所见,我尝试点击按钮“Speichern”。但奇怪的是,错误说他不能点击位置,但另一个元素是我要点击的按钮。

你知道我为什么以及如何解决这个问题?

xpath = //span[text()='Speichern'

FF = 43.0

Selenium = 2.49。

3 个答案:

答案 0 :(得分:0)

嗯,你告诉司机点击跨度,而不是按钮。尝试修改xpath以指向按钮。我认为这会奏效:

import datetime
import email
import imaplib
import mailbox


EMAIL_ACCOUNT = "your@gmail.com"
PASSWORD = "your password"

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(EMAIL_ACCOUNT, PASSWORD)
mail.list()
mail.select('inbox')
result, data = mail.uid('search', None, "UNSEEN") # (ALL/UNSEEN)
i = len(data[0].split())

for x in range(i):
    latest_email_uid = data[0].split()[x]
    result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)')
    # result, email_data = conn.store(num,'-FLAGS','\\Seen') 
    # this might work to set flag to seen, if it doesn't already
    raw_email = email_data[0][1]
    raw_email_string = raw_email.decode('utf-8')
    email_message = email.message_from_string(raw_email_string)

    # Header Details
    date_tuple = email.utils.parsedate_tz(email_message['Date'])
    if date_tuple:
        local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
        local_message_date = "%s" %(str(local_date.strftime("%a, %d %b %Y %H:%M:%S")))
    email_from = str(email.header.make_header(email.header.decode_header(email_message['From'])))
    email_to = str(email.header.make_header(email.header.decode_header(email_message['To'])))
    subject = str(email.header.make_header(email.header.decode_header(email_message['Subject'])))

    # Body details
    for part in email_message.walk():
        if part.get_content_type() == "text/plain":
            body = part.get_payload(decode=True)
            file_name = "email_" + str(x) + ".txt"
            output_file = open(file_name, 'w')
            output_file.write("From: %s\nTo: %s\nDate: %s\nSubject: %s\n\nBody: \n\n%s" %(email_from, email_to,local_message_date, subject, body.decode('utf-8')))
            output_file.close()
        else:
            continue

它确实假设只有一个元素包含该文本,并查找父元素,即您的按钮。

答案 1 :(得分:0)

异常明确表示您将click span,而button元素会收到点击,因此您需要点击button而不是{{1}如下: -

span

driver.findElement(By.cssSelector("button.hux-ui-button")).click();

已修改: - 如果您仍遇到同样的问题,请尝试使用driver.findElement(By.xpath(".//span[text()='Speichern']/parent::button")).click(); 执行点击操作,如下所示: -

JavascriptExecutor

答案 2 :(得分:0)

Sooo ......我刚问了一个Pro-Programmer;)。

我不得不用这个更新我的singelton:

public static Optional<JavascriptExecutor> getExecutor() {
WebDriver checkdriver = Driver.getWebInstance();

final JavascriptExecutor executor;

if (checkdriver instanceof JavascriptExecutor ){

    executor = (JavascriptExecutor)checkdriver;

}
else
{
    executor = null;
}
return Optional.ofNullable(executor);
}

并将其添加到实际的页面对象中:

WebElement el = Driver.getInstance().findElement(By.xpath(".//span[text()='Speichern']/parent::button"));

Driver.getExecutor().ifPresent( (executor) -> executor.executeScript("arguments[0].click()", el) ); 

现在可以了。谢谢:)